home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 September / PCgo 2008-09 (DVD).iso / interface / contents / vollversionen_6375 / 20267 / files / InstallerFiles / Data1.cab / mtc__api.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-07-06  |  109.3 KB  |  2,536 lines

  1. //=======================================================================
  2. // (c) Copyright 1990-2003, Bowne Global Solutions, Inc. All Rights Reserved
  3. //
  4. //  This work is protected by United States and international copyright
  5. //  laws and contains certain trade secret information.  All use of this
  6. //  work is governed by the terms of agreements between Bowne Global
  7. //  Solutions and its licensees or potential licensees.  Disclosure or 
  8. //  disassembly of the contents of embodied programs or algorithms is 
  9. //  prohibited.  All rights are reserved worldwide.
  10. //
  11. // File:
  12. //      MTC++api.h
  13. //
  14. // Description:
  15. // MT API C++ interface / header
  16. //
  17. // Cautions:
  18. //      
  19. //
  20. // Author: 
  21. //      John Zhang
  22. //
  23. // Creation Date:
  24. //      
  25. //
  26. // Change History:
  27. //      Date:    Initials:      Comment: 
  28. //=======================================================================
  29.  
  30. /**
  31. \file mtc++api.h
  32. This file contains the supported machine translation API interface. It is this file that
  33. should be included in any C++ application that utilizes MT SDK
  34.  
  35. \brief MT API C++ interface
  36. \copyright Bowne Global Solutions, Inc. 2003
  37. */
  38.  
  39. #ifndef MTCPlusPlusAPI_H
  40. #define MTCPlusPlusAPI_H
  41.  
  42.  
  43. #include <vector>   // STL vectors
  44. #include <string>   // STL strings
  45. #include <algorithm> //STL algorithms
  46. #include <sstream>  // Standard C++ string-like streams
  47. #include <exception> // Standard exceptions
  48. #include "windows.h"
  49. using namespace std;  // STL
  50.  
  51. #include "MTapi23.h"        //C Style API
  52. using namespace MTApi2;  // namespace of the MTtranslator2
  53.  
  54. #pragma warning( disable : 4786)  // 'wstring' as a param creates identifies longer than 255
  55.  
  56. //-----------------------------------------------------------------------------*
  57.  
  58. namespace MTCPlusPlusAPI
  59. {
  60. ////////////////////////////////////////////////////////////////////////////////
  61. //  MT Variable Types
  62. //
  63.  
  64.  
  65. typedef unsigned                MTId;
  66.  
  67. typedef wchar_t                 MTChar;
  68.  
  69.  
  70. typedef MTId                    MTLanguage;
  71.  
  72. typedef vector<MTLanguage>     MTLanguageArray;
  73. const   MTLanguage              MTNoLanguage    =  0;
  74.  
  75. typedef MTId                    MTPofs;
  76.  
  77. typedef vector<MTPofs>         MTPofsArray;
  78. const   MTPofs                  MTNoPofs        =  0;
  79.  
  80. typedef long                    MTContext;  
  81. const   MTContext               MTNoContext     = -1;
  82.  
  83. typedef MTId                    MTDomain;
  84.  
  85. typedef vector<MTDomain>       MTDomainArray;
  86. const   MTDomain                MTNoDomain      =  0;
  87.  
  88. typedef MTId                    MTOption;
  89.  
  90. typedef vector<MTOption>       MTOptionArray;
  91.  
  92. typedef MTId                    MTOptionValue;
  93.  
  94. typedef vector<MTOptionValue>  MTOptionValueArray;
  95. const   MTOptionValue           MTNoOptionValue =  0;
  96.  
  97. typedef int                     MTIndex;
  98. const   MTIndex                 MTNoIndex       = -1;
  99.  
  100. typedef int                     MTOffset;
  101. const   MTOffset                MTNoOffset      = -1;
  102.  
  103.  
  104. typedef vector<wstring>        MTStringArray;
  105.  
  106. typedef unsigned long           MTCount;
  107.  
  108. typedef int                     MTAPIFunctionIndex;
  109.  
  110. typedef unsigned                MTHeadwordIndex;
  111.  
  112. //#ifndef MTAPI_CALL
  113. //#define MTAPI_CALL      __stdcall
  114. //#endif
  115.  
  116. //typedef int (MTAPI_CALL *callBackFuncPtr)();
  117.  
  118. typedef unsigned MTResult;
  119. const MTResult MT_OK =                                0;      // Successful completion
  120. const MTResult MT_DOC_SUCCESSFUL       =            0;   // Document translated successfully
  121. const MTResult MT_FAIL =                          101;   // returned code by QuerySupporedCalls for 
  122.                                                          // the API not supported
  123.  
  124. const MTResult MTE_BARC_SERVER_ERROR =            102;      // internal error in Barcelona engine
  125. const MTResult MTE_KAMEJIMA_SERVER_ERROR =        103;      // internal error in Japanese engine
  126. const MTResult MTE_CREATE_DOMAIN_FAILED =         104;
  127. const MTResult MTE_CREATE_WORD_FAILED =           105;
  128. const MTResult MTE_DELETE_WORD_FAILED =           106;
  129. const MTResult MTE_DOMAIN_ALREADY_EXIST =         107;
  130. const MTResult MTE_EMPTY_SOURCE =                 108;
  131. const MTResult MTE_INSUFFICIENT_BUFFER =          109;  
  132. const MTResult MTE_INVALID_DOMAIN_ID =            110;
  133. const MTResult MTE_INVALID_FILE_FORMAT =          111;  // Source document is not a text or HTML file
  134. const MTResult MTE_INVALID_INTERFACE_LANGUAGE_ID =112; 
  135. const MTResult MTE_INVALID_LANGUAGE_ID =          113;
  136. const MTResult MTE_INVALID_OPTION_IDENTIFIER =    114;  
  137. const MTResult MTE_INVALID_OPTIONVALUE_IDENTIFIER= 115;
  138. const MTResult MTE_INVALID_PARAMETER =            116;  
  139. const MTResult MTE_INVALID_POFS_ID =              117;  
  140. const MTResult MTE_INVALID_WORD_ATTRIBUTE =       118;
  141. const MTResult MTE_LANGUAGE_PAIR_IN_USE =         119;
  142. const MTResult MTE_NO_REP =                       120;      // Missing representation object
  143. const MTResult MTE_NO_TRANSLATOR =                121;
  144. const MTResult MTE_SETHEADWORD_FAILED =           122;
  145. const MTResult MTE_UNFOUND_DICTIONARY_ENTRY =     123;  
  146. const MTResult MTE_UNFOUND_MORPHOLOGY =           124;  
  147. const MTResult MTE_UNIMPLEMENTED =                125;      // Function not yet implemented
  148. const MTResult MTE_GUESS_LANGUAGE_FAILED   =      126;
  149. const MTResult MTE_UNSUPPORTED =                  127;      // Function not supported
  150. const MTResult MTE_WORD_ALREADY_EXIST =           128;
  151.     
  152. //the following error codes are for ConvertLIFtoDictionary
  153. const MTResult MTE_UNABLE_TO_CREATE_CDS_FILE =        300;    // Could not open a new .cds file
  154. const MTResult MTE_UNABLE_TO_OPEN_LIF_FILE    =        301;    // Unable to open the specified LIF file
  155. const MTResult MTE_MISSING_ENGINE_LANGUAGE_FILES =    302;    // Missing any one of the linguistic files needed by the engine
  156. const MTResult MTE_HEADWORDS_OUT_OF_ORDER    =        303;    // Headwords are not in alphabetical order - non fatal
  157. const MTResult MTE_INVALID_LEMMA_FIELD =            304;    // Lemma field in LIF file contans an error
  158. const MTResult MTE_INVALID_TRANSLATION_FIELD =        305;    // Translation field in LIF file contains an error
  159. const MTResult MTE_INVALID_POS_FIELD =                306;    // Error in POS field
  160. const MTResult MTE_INVALID_ATTRIBUTE_FIELD =        307;    // Error in attribute field
  161. const MTResult MTE_ENTRY_HAS_NO_GENDER =            308;    // For Portuguese only - when attribute field has the "NoArticle" attribute
  162. const MTResult MTE_INVALID_COMMENT_FIELD =            309;    // Error in comment field
  163. const MTResult MTE_INVALID_HEADWORD_FIELD =            310;    // Error in headword field
  164. const MTResult MTE_INVALID_MORPHOLOGY_FIELD =        311;    // Invalid morphology field
  165. const MTResult MTE_INVALID_INITIALS_FIELD =            312;    
  166. const MTResult MTE_INVALID_DATE_FIELD =                313;
  167. const MTResult MTE_TRANSLATION_INTEGRITY_ISSUE =    314;
  168.  
  169. // the following error codes are for confidence score API
  170. const MTResult MTE_NO_CM_SELECTED               =   350;    // No model has been selected
  171. const MTResult MTE_NO_CM_ACTIVATED              =   351;    // No model has been activated
  172. //-----------------------------------------------------------------------------*
  173.  
  174. struct SBackMapArrayEntry
  175.     {
  176.     int targetOffset;
  177.     int targetLength;
  178.     int sourceOffset;
  179.     int sourceLength;
  180.     SBackMapArrayEntry()
  181.         {
  182.         targetOffset = -1;
  183.         targetLength = -1;
  184.         sourceOffset = -1;
  185.         sourceLength = -1;
  186.         }
  187.     };
  188.  
  189. typedef vector<SBackMapArrayEntry>     MTBackMapArray;
  190.  
  191.  
  192. typedef struct
  193.     {
  194.     int offset;
  195.     int len;
  196.     } SOffsetLengthEntry;
  197.  
  198. typedef vector<SOffsetLengthEntry>     MTOffsetLengthArray;
  199.  
  200.  
  201. typedef struct
  202.     {
  203.     int sourceIndex;
  204.     int targetIndex;
  205.     } SAssociationEntry;
  206.  
  207. typedef vector<SAssociationEntry>      MTAssociationArray;
  208.  
  209. //-----------------------------------------------------------------------------*
  210.  
  211. class MTException : public std::exception
  212.     {
  213.     std::string message_;
  214.     public:
  215.         MTException(const std::string& message) : message_(message) {}
  216.         MTException(const MTException& right)
  217.             { message_ = right.message_;  }
  218.         MTException& operator = (const MTException& right)
  219.             {
  220.             if (&right == this)
  221.                 return *this;
  222.             message_ = right.message_;
  223.             return *this;
  224.             }
  225.         const char* what() const 
  226.             { return message_.c_str(); }
  227.     };
  228.  
  229. struct MTLanguagePair
  230.     {
  231.     MTLanguage  l1; 
  232.     MTLanguage  l2;
  233.     MTLanguagePair () : l1 (MTNoLanguage), l2 (MTNoLanguage)  {}
  234.     MTLanguagePair (MTLanguage x1, MTLanguage x2) : l1 (x1), l2 (x2)  {}
  235.     };
  236.  
  237. typedef vector<MTLanguagePair>     MTLanguagePairArray;
  238.  
  239. const unsigned FAIR_SIZE = 64;      //so that it can be changed uniformly.
  240. const unsigned LARGE_SIZE = 256;
  241.  
  242. /** \class MTapi3
  243. This is the abstract base class for MT interface classes
  244. */
  245. class MTapi3
  246.     {
  247.     public:
  248.         /** Default constructor - loads the engine dll(s)
  249.         The constructor loads the engine dll, loads exported function CreateMTObject,
  250.         and creates the translator object
  251.         */
  252.         MTapi3()
  253.             {
  254.             translator = 0;
  255.  
  256.             // Load library .DLL explicitly
  257.              HINSTANCE library = LoadLibrary("BarcelonaEngineWrapper.dll");
  258.             if (library == NULL)
  259.                 {
  260.                 // failed to load DLL, log error
  261.                 throw MTException("MT engine loading error");
  262.                 }
  263.             
  264.             // Load exported function CreateMTObject
  265.             fnCreateMTobject CreateMTObject =
  266.                 (fnCreateMTobject)GetProcAddress(library,
  267.                 "CreateMTobject");
  268.             
  269.             if (CreateMTObject == NULL)
  270.                 throw MTException("CreateMTobject function not found");
  271.  
  272.             translator = CreateMTObject();
  273.  
  274.             if (translator == NULL)
  275.                 throw MTException("MT object creation error");
  276.             }
  277.  
  278.  
  279.         
  280.         /**Destructor
  281.         Releases the translator object
  282.         */
  283.         ~MTapi3()
  284.             {
  285.             if (translator)
  286.                 {
  287.                 translator->ReleaseMT();
  288.                 translator = 0;
  289.                 }
  290.             }
  291.  
  292.                
  293.         /**This function queries the translation engine for the number of single-direction
  294.         language pairs available for translation.
  295.         \return Number of language pairs available for translation
  296.         Possible errors:
  297.         MTE_BARC_SERVER_ERROR - Internal engine error
  298.         */
  299.         MTCount CountAvailableLanguagePairs()
  300.             {
  301.             unsigned  int count = 0;
  302.             translator->CountAvailableLanguagePairs(&count);
  303.             return count;
  304.             }
  305.         
  306.         /** This function queries the translation engine for the number of translation
  307.         options available for the active language pair.
  308.         Some translation engines have special parameters or options that affect how
  309.         sentences, words, or documents are translated. Each human language has certain
  310.         options, such as the masculine and feminine forms of address, and formal and
  311.         informal pronouns.
  312.         \return Number of available translation options for the active language pair
  313.         Possible errors:
  314.         MTE_NO_TRANSLATOR - No language pair is set
  315.         MTE_BARC_SERVER_ERROR - Internal engine error
  316.         */
  317.         MTCount CountAvailableOptions()
  318.             {
  319.             unsigned  int count = 0;
  320.             translator->CountAvailableOptions(&count);
  321.             return count;
  322.             }
  323.         
  324.         /**This function queries the translation engine for the number of discrete option
  325.         values available for the specified translation option.
  326.         Each translation option may take on a set of discrete values.
  327.         \return Number of discrete option values available for the specified translation option
  328.         Possible errors:
  329.         MTE_BARC_SERVER_ERROR - Internal engine error
  330.         MTE_NO_TRANSLATOR - No language pair is set
  331.         MTE_INVALID_OPTION_IDENTIFIER - <c>option</c> parameter is not one of the values reported by <c>GetAvailableOptions</c>
  332.         */
  333.         MTCount CountAvailableOptionValues(MTOption option)
  334.             {
  335.             unsigned  int count = 0;
  336.             translator->CountAvailableOptionValues(option, &count);
  337.             return count;
  338.             }
  339.         
  340.         /**This function queries the translation engine for the number of available
  341.         parts of speech for the active language pair.
  342.         \return Number of available parts of speech for the active language pair.
  343.         Possible errors:
  344.         MTE_NO_TRANSLATOR - No language pair is set
  345.         MTE_BARC_SERVER_ERROR - Internal engine error
  346.         */
  347.         MTCount CountAvailablePartsOfSpeech()
  348.             {
  349.             unsigned  int count = 0;
  350.             translator->CountAvailablePartsOfSpeech(&count);
  351.             return count;
  352.             }
  353.         
  354.         /**This function gets the number of global variables for the active language pair
  355.         \return Number of global variables for the active language pair
  356.         Possible errors:
  357.         MTE_NO_TRANSLATOR - No language pair is set
  358.         MTE_BARC_SERVER_ERROR - Internal engine error
  359.         */
  360.         MTCount CountAvailableVariables()
  361.             {
  362.             unsigned  int count = 0;
  363.             translator->CountAvailableVariables(&count);
  364.             return count;
  365.             }
  366.         
  367.         /**This function queries the translation engine for the number of specific
  368.         subject domain dictionaries or subject domains available for the active language pair.
  369.         \param domain The domain ID for the subdomain, or zero if we want the count of all
  370.         root domains.
  371.         \return The number of specific subject domain dictionaries or subject domains
  372.         available for the active language pair.
  373.         Possible errors:
  374.         MTE_NO_TRANSLATOR - No language pair is set
  375.         MTE_BARC_SERVER_ERROR - Internal engine error
  376.         */
  377.         MTCount  CountAvailableSubjectDomains   (MTDomain domain)
  378.             {
  379.             unsigned  int count = 0;
  380.             translator->CountAvailableSubjectDomains(domain, &count);
  381.             return count;
  382.             }
  383.         
  384.         /**This function retrieves the active language pair.
  385.         The language pair consists of the source and target language identifiers
  386.         previously selected as the language pair.
  387.         \param langPair A reference to an MTLanguagePair struct. Upon completion,
  388.         field \a l1 of \a langPair contains the source language identifier and field \a l2 
  389.         contains the target language identifier.
  390.         \return Error code.
  391.         Possible errors: none
  392.         */
  393.         MTResult GetActiveLanguagePair(MTLanguagePair & langPair)
  394.             {
  395.             MTLanguage srcLang = MTAPI_LANG_NEUTRAL;
  396.             MTLanguage trgLang = MTAPI_LANG_NEUTRAL;
  397.             translator->GetActiveLanguagePair(&srcLang, &trgLang);
  398.  
  399.             langPair.l1 = srcLang;
  400.             langPair.l2 = trgLang;
  401.             return translator->GetMTError();
  402.             }
  403.                 
  404.         /**This function retrieves an array of language identifiers for the
  405.         source and target language pairs.
  406.         \param langPairs A reference to an \a MTLanguagePairArray vector. Upon completion,
  407.         each element contains an \a MTLanguagePair struct where field \a l1 contains the source
  408.         language identifier and field \a l2 contains the target language identifier.
  409.         \return Error code.
  410.         Possible errors:        
  411.         MTE_BARC_SERVER_ERROR - Internal engine error
  412.         */
  413.         MTResult GetAvailableLanguagePairs(MTLanguagePairArray & langPairs)
  414.             {
  415.             MTerror nError = MT_OK;
  416.             unsigned nSize = FAIR_SIZE * 2;
  417.             vector<MTLanguage> langArray(nSize, 0);
  418.  
  419.             nError = translator->GetAvailableLanguagePairs( &langArray[0], &nSize );
  420.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  421.                 {
  422.                 langArray.reserve(nSize);
  423.                 fill(langArray.begin(), langArray.end(), 0);
  424.                 nError = translator->GetAvailableLanguagePairs( &langArray[0], &nSize );
  425.                 }
  426.  
  427.             if (nError == MT_OK)
  428.                 {
  429.                 langPairs.clear();
  430.                 for (unsigned i = 0; i < nSize; i += 2)
  431.                     {
  432.                     langPairs.push_back(MTLanguagePair(langArray[i], langArray[i+1]));
  433.                     }
  434.                 }
  435.  
  436.             return translator->GetMTError();
  437.             }
  438.  
  439.         
  440.         /**This function retrieves an array of option identifiers for the 
  441.         translation options available for the active language pair.
  442.         \param options A reference to an \a MTOptionArray vector. Upon completion,
  443.         each element contains the list of available option identifiers for the
  444.         active language pair.
  445.         \return Error code.
  446.         Possible errors:
  447.         MTE_NO_TRANSLATOR - No language pair is set
  448.         MTE_BARC_SERVER_ERROR - Internal engine error
  449.         */
  450.         MTResult GetAvailableOptions(MTOptionArray & options)
  451.             {
  452.             MTerror nError = MT_OK;
  453.             unsigned nSize = FAIR_SIZE;
  454.             vector <MTOption> optArray(nSize, 0);
  455.  
  456.             nError = translator->GetAvailableOptions( &optArray[0], &nSize );
  457.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  458.                 {
  459.                 optArray.reserve(nSize);
  460.                 fill(optArray.begin(), optArray.end(), 0);
  461.                 nError = translator->GetAvailableOptions( &optArray[0], &nSize );
  462.                 }
  463.  
  464.             options.clear();
  465.             if (nError == MT_OK)
  466.                 copy(optArray.begin(), optArray.begin() + nSize, back_inserter(options));
  467.             
  468.             return translator->GetMTError();
  469.             }
  470.         
  471.         /**This function retrieves an array of option value identifiers for the
  472.         specified translation option.
  473.         \param option An option identifier that specifies the option for which values
  474.         are retrieved.
  475.         \param optValues A reference to an MTOptionValueArray vector. Upon completion,
  476.         each element contains the list of available option value identifiers for the
  477.         specified translation option.
  478.         \return Error code.
  479.         Possible errors:
  480.         MTE_NO_TRANSLATOR - No language pair is set
  481.         MTE_INVALID_OPTION_IDENTIFIER - <c>option</c> parameter is not one of the values reported by <c>GetAvailableOptions</c>
  482.         MTE_BARC_SERVER_ERROR - Internal engine error
  483.         */
  484.         MTResult GetAvailableOptionValues(MTOption option, MTOptionValueArray& optValues)
  485.             {
  486.             MTerror nError = MT_OK;
  487.             unsigned nSize = FAIR_SIZE;
  488.             vector <MTOptionValue> optValueArray(nSize, 0);
  489.  
  490.             nError = translator->GetAvailableOptionValues( option, &optValueArray[0], &nSize );
  491.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  492.                 {
  493.                 optValueArray.reserve(nSize);
  494.                 fill(optValueArray.begin(), optValueArray.end(), 0);
  495.                 nError = translator->GetAvailableOptionValues( option, &optValueArray[0], &nSize );
  496.                 }
  497.  
  498.             optValues.clear();
  499.             if (nError == MT_OK)
  500.                 copy (optValueArray.begin(), optValueArray.begin() + nSize, back_inserter(optValues));
  501.  
  502.             return translator->GetMTError();
  503.             }
  504.         
  505.         /**This function retrieves an array of global variables for the active language pair.
  506.         \param variables A reference to an \a MTStringArray vector. Upon completion, each
  507.         element contains the name of a global variable
  508.         \return Error code.
  509.         Possible errors:
  510.         MTE_NO_TRANSLATOR - No language pair is set
  511.         MTE_BARC_SERVER_ERROR - Internal engine error
  512.         */
  513.         MTResult GetAvailableVariables(MTStringArray& variables)
  514.             {
  515.             MTerror nError = MT_OK;            
  516.             unsigned nSize = LARGE_SIZE;
  517.             vector <MTchar> varNames (nSize);
  518.             varNames[0] = 0;
  519.  
  520.             nError = translator->GetAvailableVariables(&varNames[0], &nSize);
  521.  
  522.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  523.                 {
  524.                 varNames.resize(nSize);
  525.                 varNames[0] = 0;
  526.                 nError = translator->GetAvailableVariables(&varNames[0], &nSize);
  527.                 }
  528.             //fill the variables
  529.             variables.clear();
  530.             if (nError == MT_OK)
  531.                 {
  532.                 MTstringarray ptr = &varNames[0];                
  533.                 wstring aName;
  534.                 while( ptr - &varNames[0] < (int)nSize )
  535.                     {
  536.                     aName = wstring(ptr);
  537.                     ptr += aName.size();
  538.                     ++ptr;  //null-terminate current block
  539.                     ++ptr; 
  540.                     variables.push_back(aName);
  541.                     }                }
  542.             return translator->GetMTError();
  543.             }
  544.  
  545.         
  546.         /**This function retrieves an array of part of speech identifiers for the parts
  547.         of speech available for the active language pair.
  548.         \param allPofs A reference to an \a MTPofSArray vector where each element contains
  549.         the list of part-of-speech identifiers for the active language pair.
  550.         \return Error code.
  551.         Possible errors:
  552.         MTE_NO_TRANSLATOR - No language pair is set
  553.         MTE_BARC_SERVER_ERROR - Internal engine error
  554.         */
  555.         MTResult GetAvailablePartsOfSpeech(MTPofsArray & allPofs)
  556.             {
  557.             MTerror nError = MT_OK;
  558.             unsigned nSize = FAIR_SIZE;
  559.             vector <MTPofs> pofsArray(nSize, 0);
  560.  
  561.             nError = translator->GetAvailablePartsOfSpeech( &pofsArray[0], &nSize );
  562.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  563.                 {
  564.                 pofsArray = vector<MTPofs>(nSize,0);
  565.                 nError = translator->GetAvailablePartsOfSpeech( &pofsArray[0], &nSize );
  566.                 }
  567.             allPofs.clear();
  568.             if (nError == MT_OK)
  569.                 copy (pofsArray.begin(), pofsArray.begin() + nSize, back_inserter(allPofs));
  570.  
  571.             return translator->GetMTError();
  572.             }
  573.  
  574.         
  575.         /**This function retrieves an array of subject domain descriptions under the
  576.         specified subject domain that are available for the active language pair.
  577.         \param domain Specifies the subject domain identifier whose sub domains are to
  578.         be retrieved. A value of zero or \a MT_DOMAIN_UNSPECIFIED returns the number of root
  579.         domains.
  580.         \param domains A reference to an \a MTStringArray vector where each element contains
  581.         the text description of a subject domain.
  582.         \return Error code.
  583.         Possible errors:
  584.         MTE_NO_TRANSLATOR - No language pair is set
  585.         MTE_BARC_SERVER_ERROR - Internal engine error
  586.         */
  587.         MTResult GetAvailableSubjectDomains(MTDomain domain, MTStringArray& domains)
  588.             {
  589.             MTerror nError = MT_OK;
  590.             
  591.             unsigned nSize = LARGE_SIZE;
  592.             vector <MTchar> domainNames(nSize);
  593.             domainNames[0] = 0;
  594.  
  595.             nError = translator->GetAvailableSubjectDomains(domain, &domainNames[0], &nSize);
  596.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  597.                 {
  598.                 domainNames = vector <MTchar>(nSize);
  599.                 domainNames[0] = 0;
  600.                 nError = translator->GetAvailableSubjectDomains(domain, &domainNames[0], &nSize);
  601.                 }
  602.  
  603.             //fill the domains
  604.             domains.clear();
  605.             if (nError == MT_OK)
  606.                 {
  607.                 MTstringarray ptr;
  608.                 ptr = &domainNames[0];
  609.                 unsigned curPos = 0;
  610.                 wstring aName;
  611.                 while( ptr - &domainNames[0] < (int)nSize )
  612.                     {
  613.                     aName = wstring(ptr);
  614.                     ptr += aName.size();
  615.                     ++ptr;  //null-terminate current block
  616.                     ++ptr; 
  617.                     domains.push_back(aName);
  618.                     }
  619.                 }
  620.             return translator->GetMTError();
  621.             }
  622.  
  623.         
  624.         /**This function retrieves an array of subject domain identifiers under the
  625.         specified subject domain that are available for the active language pair.
  626.         \param domain Specifies the subject domain identifier whose sub domains are to
  627.         be retrieved. A value of zero or \a MT_DOMAIN_UNSPECIFIED returns the number of root
  628.         domains.
  629.         \param domains A reference to an \a MTDomainArray vector where each element contains
  630.         the domain identifier of a subject domain.
  631.         \return Error code.
  632.         Possible errors:
  633.         MTE_NO_TRANSLATOR - No language pair is set
  634.         MTE_BARC_SERVER_ERROR - Internal engine error
  635.         */        
  636.         MTResult GetAvailableSubjectDomains(MTDomain domain, MTDomainArray& domains)
  637.             {
  638.             MTerror nError = MT_OK;
  639.             unsigned nSize = FAIR_SIZE;
  640.             vector<MTDomain> domainArray(nSize, 0);
  641.             
  642.             nError = translator->GetAvailableSubjectDomains( domain, &domainArray[0], &nSize );
  643.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  644.                 {
  645.                 domainArray = vector<MTDomain>(nSize, 0);
  646.                 nError = translator->GetAvailableSubjectDomains( domain, &domainArray[0], &nSize );
  647.                 }
  648.  
  649.             if (nError == MT_OK)
  650.                 copy (domainArray.begin(), domainArray.begin() + nSize, back_inserter(domains));
  651.  
  652.             return translator->GetMTError();
  653.             }
  654.         
  655.         /**This function retrieves the description of the specified language identifier
  656.         localized in the specified interface language.
  657.         \param interfaceLang A language identifier of the interface language to use for
  658.         localization of the returned language description.
  659.         \param lang A language identifier of the language text description to be returned.
  660.         \return A string that contains the description of the input language identifier 
  661.         localized in the specified interface language.
  662.         Possible errors:
  663.         MTE_INVALID_INTERFACE_LANGUAGE_ID - Language id is not MTAPI_LANG_ENGLISH (9 under MS Windows)
  664.         MTE_BARC_SERVER_ERROR - Internal engine error
  665.         */
  666.         wstring GetLanguageDescription(MTLanguage interfaceLang, MTLanguage lang)
  667.             {
  668.             MTerror nError = MT_OK;
  669.             unsigned nSize = FAIR_SIZE;
  670.             
  671.             vector <MTChar> langDescription(nSize);
  672.             langDescription[0] = 0;
  673.  
  674.             nError = translator->GetLanguageDescription( interfaceLang, lang, &langDescription[0], &nSize);
  675.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  676.                 {
  677.                 langDescription = vector<MTChar>(nSize);
  678.                 langDescription[0] = 0;
  679.                 nError = translator->GetLanguageDescription( interfaceLang, lang, &langDescription[0], &nSize);
  680.                 }
  681.  
  682.             wstring langDesrpt;
  683.             if (nError == MT_OK)
  684.                 langDesrpt = &langDescription[0];
  685.  
  686.             return langDesrpt;
  687.             }
  688.         
  689.         /**This function retrieves a description of the specified option identifier
  690.         localized in the specified interface language.
  691.         \param interfaceLang A language identifier of the interface language to use for 
  692.         localization of the returned option description.
  693.         \param option A translation option identifier.
  694.         \return A string that contains the description of the specified option identifier
  695.         localized in the specified interface language.
  696.         Possible errors:
  697.         MTE_NO_TRANSLATOR - No language pair is set
  698.         MTE_INVALID_INTERFACE_LANGUAGE_ID - Language id is not MTAPI_LANG_ENGLISH (9 under MS Windows)
  699.         MTE_INVALID_OPTION_IDENTIFIER - <c>option</c> parameter is not one of the values reported by <c>GetAvailableOptions</c>
  700.         MTE_BARC_SERVER_ERROR - Internal engine error
  701.         */
  702.         wstring GetOptionDescription(MTLanguage interfaceLang, MTOption option)
  703.             {
  704.             MTerror nError = MT_OK;
  705.             unsigned nSize = FAIR_SIZE;
  706.             
  707.             vector <MTChar> optDescription (nSize);
  708.             optDescription[0] = 0;
  709.  
  710.             nError = translator->GetOptionDescription( interfaceLang, option, &optDescription[0], &nSize);
  711.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  712.                 {
  713.                 optDescription = vector<MTChar> (nSize);
  714.                 optDescription[0] = 0;
  715.                 nError = translator->GetOptionDescription( interfaceLang, option, &optDescription[0], &nSize);
  716.                 }
  717.  
  718.             wstring optDesrpt;
  719.             if (nError == MT_OK)
  720.                 optDesrpt = &optDescription[0];
  721.  
  722.             return optDesrpt;
  723.             }
  724.         
  725.         /**This function retrieves the description of the specified option value identifier
  726.         localized in the specified interface language.
  727.         \param interfaceLang A language identifier of the interface language to use for 
  728.         localization of the returned option value description.
  729.         \param option A translation option identifier whose selected value description is
  730.         to be returned.
  731.         \param optValue An option value identifier whose description is to be returned.
  732.         \return A string that contains the description of the specified option value
  733.         identifier localized in the specified interface language
  734.         Possible errors:
  735.         MTE_NO_TRANSLATOR - No language pair is set
  736.         MTE_INVALID_INTERFACE_LANGUAGE_ID - Language id is not MTAPI_LANG_ENGLISH (9 under MS Windows)
  737.         MTE_INVALID_OPTION_IDENTIFIER - <c>option</c> parameter is not one of the values reported by <c>GetAvailableOptions</c>
  738.         MTE_INVALID_PARAMETER - Internal engine error
  739.         MTE_INVALID_LANGUAGE_ID - Internal engine error
  740.         MTE_BARC_SERVER_ERROR - Internal engine error
  741.         */
  742.         wstring GetOptionValueDescription(MTLanguage interfaceLang, MTOption option, MTOptionValue optValue)
  743.             {
  744.             MTerror nError = MT_OK;
  745.             unsigned nSize = FAIR_SIZE;
  746.             
  747.             vector<MTChar> optDescription (nSize);
  748.             optDescription[0] = 0;
  749.  
  750.             nError = translator->GetOptionValueDescription( interfaceLang, option, optValue, &optDescription[0], &nSize);
  751.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  752.                 {
  753.                 optDescription = vector<MTChar>(nSize);
  754.                 optDescription[0] = 0;
  755.                 nError = translator->GetOptionValueDescription( interfaceLang, option, optValue, &optDescription[0], &nSize);
  756.                 }
  757.  
  758.             wstring optDesrpt;
  759.             if (nError == MT_OK)
  760.                 optDesrpt = &optDescription[0];
  761.  
  762.             return optDesrpt;
  763.             }
  764.         
  765.         /**This function retrieves the description of the specified part-of-speech
  766.         identifier localized in the specified interface language.
  767.         \param interfaceLang A language identifier of the interface language to use for
  768.         localization of the returned part of speech description.
  769.         \param pofs A part-of-speech identifier.
  770.         \return A string that contains the description of the part-of-speech identifier
  771.         localized in the specified interface language.
  772.         Possible errors:
  773.         MTE_NO_TRANSLATOR - No language pair is set
  774.         MTE_INVALID_INTERFACE_LANGUAGE_ID - Language id is not MTAPI_LANG_ENGLISH (9 under MS Windows)
  775.         MTE_BARC_SERVER_ERROR - Internal engine error
  776.         */
  777.         wstring GetPartOfSpeechDescription(MTLanguage interfaceLang, MTPofs pofs) 
  778.             {
  779.             MTerror nError = MT_OK;
  780.             unsigned nSize = FAIR_SIZE;
  781.             
  782.             vector <MTChar> pofsDescription(nSize);
  783.             pofsDescription[0] = 0;
  784.  
  785.             nError = translator->GetPartOfSpeechDescription( interfaceLang, pofs, &pofsDescription[0], &nSize );
  786.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  787.                 {
  788.                 pofsDescription = vector<MTChar> (nSize);
  789.                 pofsDescription[0] = 0;
  790.                 nError = translator->GetPartOfSpeechDescription( interfaceLang, pofs, &pofsDescription[0], &nSize );
  791.                 }
  792.  
  793.             wstring pofsDesrpt;
  794.             if (nError == MT_OK)
  795.                 pofsDesrpt = &pofsDescription[0];
  796.  
  797.             return pofsDesrpt;
  798.             }
  799.         
  800.         /**This function retrieves the description of the specified subject domain
  801.         identifier localized in the specified interface language.
  802.         \param interfaceLang A language identifier of the interface language to use for
  803.         localization of the returned subject domain description.
  804.         \param domain A subject domain identifier.
  805.         \return A string that contains the description of the specified subject domain
  806.         identifier localized in the specified interface language.
  807.         Possible errors:
  808.         MTE_NO_TRANSLATOR - No language pair is set
  809.         MTE_INVALID_INTERFACE_LANGUAGE_ID - Language id is not MTAPI_LANG_ENGLISH (9 under MS Windows)
  810.         MTE_BARC_SERVER_ERROR - Internal engine error
  811.         */
  812.         wstring GetSubjectDomainDescription(MTLanguage interfaceLang, MTDomain domain)
  813.             {
  814.             MTerror nError = MT_OK;
  815.             unsigned nSize = FAIR_SIZE;
  816.             
  817.             vector <MTChar> domainDescription (nSize);
  818.             domainDescription[0] = 0;
  819.  
  820.             nError = translator->GetSubjectDomainDescription( interfaceLang, domain, &domainDescription[0], &nSize );
  821.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  822.                 {
  823.                 domainDescription = vector<MTChar>(nSize);
  824.                 domainDescription[0] = 0;
  825.                 nError = translator->GetSubjectDomainDescription( interfaceLang, domain, &domainDescription[0], &nSize );
  826.                 }
  827.  
  828.             wstring domainDesrpt;
  829.             if (nError == MT_OK)
  830.                 domainDesrpt = &domainDescription[0];
  831.  
  832.             return domainDesrpt;
  833.             }
  834.         
  835.         /**This function sets the active language pair. This language pair consists of a
  836.         source and target language identifier for translation.
  837.         \param srcLang The language identifier that specifies the source language for the
  838.         language pair.
  839.         \param trgLang The language identifier that specifies the target language for the
  840.         language pair.
  841.         \return Error code.
  842.         Possible errors:
  843.         MTE_INVALID_LANGUAGE_ID - Invalid source language, target language or language pair
  844.         MTE_BARC_SERVER_ERROR - Internal engine error
  845.         */
  846.         MTResult SetActiveLanguagePair(const MTLanguage srcLang, const MTLanguage trgLang)
  847.             {
  848.             translator->SetActiveLanguagePair( srcLang, trgLang);
  849.             return translator->GetMTError();
  850.             }
  851.  
  852.  
  853.         
  854.         /**This function loads all available language pairs from the specified directory. 
  855.         The dictionary and rule files for the specified languages must be in the specified
  856.         directory.
  857.         \param path A string that specifies the directory path where the language pair(s)
  858.         are located.
  859.         \return Error code.
  860.         Possible errors:
  861.         MTE_INVALID_PARAMETER - <c>path</c> parameter is invalid path or no language pairs found in the path
  862.         MTE_BARC_SERVER_ERROR - Internal engine error
  863.         */
  864.         MTResult LoadAllLanguagePairs(const wstring& path)
  865.             {
  866.             translator->LoadAllLanguagePairs( (const MTstring )path.c_str() );
  867.             return translator->GetMTError();
  868.             }
  869.  
  870.         
  871.         /**This function loads the requested subject domain dictionary for the specified
  872.         language pair into memory for the translation engine to use.
  873.         \param langPairID A language pair to load.
  874.         \param path A string that specifies the directory path where the language pair(s)
  875.         are located.
  876.         \param domain The domain ID of the requested domainName
  877.         \param domainName A string that specifies the domain (dictionary) name to load.
  878.         \return Error code.
  879.         Possible errors:
  880.         MTE_INVALID_PARAMETER - Either <c>domainName</c> is "GEN" or internal engine error
  881.         MTE_BARC_SERVER_ERROR - Internal engine error
  882.         */
  883.         MTResult LoadDomainDictionary(const MTLanguagePair& langPairID, const wstring& path, 
  884.                                                          MTDomain& domain, const wstring& domainName )
  885.             {
  886.             translator->LoadDomainDictionary(langPairID.l1, langPairID.l2, (const MTstring )path.c_str(), 
  887.                                                          &domain, (const MTstring )domainName.c_str() );
  888.             return translator->GetMTError();
  889.             }
  890.         
  891.         /**This function loads a specified language pair from the specified directory.
  892.         \param langPairID A language pair to load.
  893.         \param path A string that specifies the directory path where the language pair(s)
  894.         are located.
  895.         \return Error code.
  896.         Possible errors:
  897.         MTE_INVALID_PARAMETER - <c>path</c> parameter is invalid path or no language pairs found in the path
  898.         MTE_BARC_SERVER_ERROR - Internal engine error
  899.         */
  900.         MTResult LoadLanguagePair(const MTLanguagePair& langPairID, const wstring& path)
  901.             {
  902.             translator->LoadLanguagePair(langPairID.l1, langPairID.l2, (const MTstring)path.c_str());
  903.             return translator->GetMTError();
  904.             } 
  905.         
  906.         /**This function unloads all previously loaded language pairs, and closes all
  907.         corresponding rule and dictionary files.
  908.         \return Error code.
  909.         Possible errors:        
  910.         MTE_BARC_SERVER_ERROR - Internal engine error
  911.         */
  912.         MTResult UnloadAllLanguagePairs()
  913.             {
  914.             translator->UnloadAllLanguagePairs();
  915.             return translator->GetMTError();
  916.             }
  917.         
  918.         /**function unloads the requested subject domain dictionary for the specified
  919.         language pair. This function also unloads the requested user-created (custom)
  920.         dictionary.
  921.         \result Error code.
  922.         Possible errors:
  923.         MTE_INVALID_PARAMETER - <c>domain</c> is 0 (GEN)
  924.         MTE_BARC_SERVER_ERROR - Internal engine error
  925.         */
  926.         MTResult UnloadDomainDictionary (const MTLanguagePair& langPairID, MTDomain domain )
  927.             {
  928.             translator->UnloadDomainDictionary(langPairID.l1, langPairID.l2, domain );
  929.             return translator->GetMTError();
  930.             }
  931.  
  932.         
  933.         /**This function unloads the specified source-target language pair and closes the
  934.         corresponding rule and dictionary files.
  935.         \return Error code.
  936.         Possible errors:
  937.         MTE_BARC_SERVER_ERROR - Internal engine error
  938.         */
  939.         MTResult UnloadLanguagePair(const MTLanguagePair& langPairID)
  940.             {
  941.             translator->UnloadLanguagePair(langPairID.l1, langPairID.l2 );
  942.             return translator->GetMTError();
  943.             }
  944.  
  945.       
  946.         /**This function frees the memory allocated for the machine translation engine and 
  947.         restores all resources to the system.
  948.         \result Error code.
  949.         Possible errors: none
  950.         */
  951.         MTResult ReleaseMT( void )
  952.             {
  953.             translator->ReleaseMT();
  954.             translator = 0;
  955.             return MT_OK;
  956.             }
  957.  
  958.     protected:
  959.         MTtranslator2 *  translator;
  960.     };
  961.  
  962.  
  963. //-----------------------------------------------------------------------------*
  964.  
  965. /** \class MTdictionary3
  966. Implements some dictionary related functions
  967. */
  968. class MTdictionary3 : public MTapi3
  969.     {
  970.     public:
  971.         //! Default constructor        
  972.         MTdictionary3(){}
  973.  
  974.         
  975.         //! Destructor
  976.         virtual ~MTdictionary3(){}
  977.  
  978.         
  979.         /**This function creates a new subject domain with its description.
  980.  
  981.         The file extension of custom dictionaries is CDS. The file names begin
  982.         with the language direction; followed by the name you give the domain when
  983.         you create it. For example, if you create a custom dictionary and name it
  984.         "Astronomy" using the English-French language pair, the file names are:
  985.         efastronomy.cds and feastronomy.cds.
  986.  
  987.         \param domainName The name of the new domain.
  988.         \param domainDescription The description of the new domain (optional).
  989.         \return Error code.
  990.         Possible errors:
  991.         MTE_NO_TRANSLATOR - No language pair is set
  992.         MTE_CREATE_DOMAIN_FAILED - <c>domainName</c> is either "user" or "gen" (case insensitive)
  993.         MTE_DOMAIN_ALREADY_EXIST - The domain is already loaded
  994.         MTE_INVALID_LANGUAGE_ID - The inverse direction is not loaded
  995.         MTE_BARC_SERVER_ERROR - Internal engine error
  996.         */
  997.         MTResult CreateDomain(const wstring & domainName, const wstring &domainDescription)
  998.             {
  999.             translator->CreateDomain((const MTstring)domainName.c_str(), (const MTstring)domainDescription.c_str());
  1000.             return translator->GetMTError();
  1001.             }
  1002.         
  1003.         /**This function creates a new lexical entry.
  1004.         This lexical entry specifies both the headword and translation of the new
  1005.         lexical entry.
  1006.         \param translation The lexical entry for creation. This string is in word/attribute
  1007.         format and must contain at least a headword and translation field.
  1008.         \return Error code.
  1009.          Possible errors:
  1010.         MTE_NO_TRANSLATOR - No language pair is set
  1011.         MTE_INVALID_WORD_ATTRIBUTE - <c>translation</c> missing one of: headword, translation, pofs, morphology, or domain is invalid 
  1012.         MTE_WORD_ALREADY_EXIST - The translation is already in the dictionary
  1013.         MTE_CREATE_WORD_FAILED - Internal engine error
  1014.         MTE_BARC_SERVER_ERROR - Internal engine error
  1015.         */
  1016.         MTResult CreateTranslation(const wstring & translation)
  1017.             {
  1018.             translator->CreateTranslation((const MTstring)translation.c_str());
  1019.             return translator->GetMTError();
  1020.             }
  1021.         
  1022.         /**This function deletes a lexical entry.
  1023.         \param translation The lexical entry for deletion. This string is in word/attribute
  1024.         format and must contain a headword and translation field.
  1025.         \return Error code.
  1026.          Possible errors:
  1027.         MTE_NO_TRANSLATOR - No language pair is set
  1028.         MTE_INVALID_WORD_ATTRIBUTE - <c>translation</c> missing one of: headword, translation, pofs, morphology, or domain is invalid 
  1029.         MTE_UNFOUND_DICTIONARY_ENTRY - The translation was not found
  1030.         MTE_DELETE_WORD_FAILED - Internal engine error
  1031.         MTE_BARC_SERVER_ERROR - Internal engine error
  1032.         */
  1033.         MTResult DeleteTranslation(const wstring & translation)
  1034.             {
  1035.             translator->DeleteTranslation((const MTstring)translation.c_str());
  1036.             return translator->GetMTError();
  1037.             }
  1038.         
  1039.         /** This function retrieves a list of possible morphology attributes, or inflection
  1040.         patterns, for the uninflected headword.
  1041.         \param word The uninflected headword for which morphology attributes are retrieved.
  1042.         This string is in word/attribute format and must contain a headword and translation
  1043.         field.
  1044.         \return Error code.
  1045.           Possible errors:
  1046.         MTE_NO_TRANSLATOR - No language pair is set
  1047.         MTE_INVALID_WORD_ATTRIBUTE - <c>translation</c> missing one of: word, pofs
  1048.         MTE_BARC_SERVER_ERROR - Internal engine error
  1049.         */
  1050.         MTStringArray GetAvailableMorphologies(const wstring & word)
  1051.             {
  1052.             MTerror nError = MT_OK;
  1053.             MTStringArray availableMorphs;
  1054.             unsigned nSize = LARGE_SIZE;
  1055.             vector <MTChar> morphWords(nSize); 
  1056.             morphWords[0] = 0;
  1057.  
  1058.             nError = translator->GetAvailableMorphologies( (const MTstring)word.c_str(), &morphWords[0], &nSize );
  1059.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  1060.                 {
  1061.                 morphWords = vector<MTChar>(nSize);
  1062.                 morphWords[0] = 0;
  1063.                 nError = translator->GetAvailableMorphologies( (const MTstring)word.c_str(), &morphWords[0], &nSize );
  1064.                 }
  1065.  
  1066.             //fill the availableMorphs
  1067.             if (nError == MT_OK)
  1068.                 {
  1069.                 MTstringarray ptr;
  1070.                 ptr = &morphWords[0];
  1071.                 unsigned curPos = 0;
  1072.                 wstring aMorph;
  1073.                 while( ptr - &morphWords[0] < (int)nSize )
  1074.                     {
  1075.                     aMorph = wstring(ptr);
  1076.                     ptr += aMorph.size();
  1077.                     ++ptr;  //null-terminate current block
  1078.                     ++ptr; 
  1079.                     availableMorphs.push_back(aMorph);
  1080.                     }
  1081.                 }
  1082.             return availableMorphs;
  1083.             }
  1084.  
  1085.         
  1086.         /**Not implemented
  1087.  
  1088.         */
  1089.         wstring GetHeadword(MTHeadwordIndex headIndex)
  1090.             {
  1091.             MTerror nError = MT_OK;
  1092.             unsigned nSize = FAIR_SIZE;
  1093.             vector<MTChar> head(nSize);
  1094.             head[0] = 0;
  1095.  
  1096.             nError = translator->GetHeadword( headIndex, &head[0], &nSize );
  1097.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  1098.                 {
  1099.                 head = vector<MTChar>(nSize);
  1100.                 head[0] = 0;
  1101.                 nError = translator->GetHeadword( headIndex, &head[0], &nSize );
  1102.                 }
  1103.  
  1104.             wstring headWord;
  1105.             if (nError == MT_OK)
  1106.                 headWord = wstring(&head[0], nSize);
  1107.  
  1108.             return headWord;
  1109.             }
  1110.         
  1111.         /**Not implemented
  1112.         */
  1113.         MTCount GetHeadwordCount() 
  1114.             {
  1115.             MTerror nError = MT_OK;
  1116.             unsigned int headCount = 0;
  1117.             nError = translator->GetHeadwordCount(&headCount);
  1118.             return headCount;
  1119.             }
  1120.         
  1121.         /**Not implemented
  1122.         */
  1123.         MTHeadwordIndex GetHeadwordIndex(const wstring & head)
  1124.             {
  1125.             MTerror nError = MT_OK;
  1126.             unsigned int headIndex = 0;
  1127.             nError = translator->GetHeadwordIndex( (const MTstring)head.c_str(), &headIndex);
  1128.             return headIndex;
  1129.             }
  1130.         
  1131.         /**This function retrieves the translation entries for the specified headword.
  1132.  
  1133.         More information about the headword, such as part of speech and word attributes,
  1134.         may be needed to obtain the best translation. The headword parameter must be in
  1135.         word/attribute format.
  1136.  
  1137.         The output array is in word/attribute format and contains translation and headword fields. The
  1138.         order of the elements in the array specifies the priority of each translation entry. The first element
  1139.         in the array has the highest priority; it is from the highest priority subject domain that contains an
  1140.         appropriate headword.
  1141.         \param head The translation entries for the specified headword.
  1142.         \return The translation entries for the specified headword.
  1143.           Possible errors:
  1144.         MTE_NO_TRANSLATOR - No language pair is set
  1145.         MTE_INVALID_WORD_ATTRIBUTE - <c>translation</c> missing the word attribute
  1146.         MTE_UNFOUND_DICTIONARY_ENTRY - The word was not found in the loaded dictionaries.
  1147.         MTE_BARC_SERVER_ERROR - Internal engine error
  1148.         */
  1149.         MTStringArray GetHeadwordTranslations(const wstring & head)
  1150.             {
  1151.             MTerror nError = MT_OK;
  1152.             unsigned nSize = LARGE_SIZE;
  1153.             vector<MTChar> headTranslations(nSize);
  1154.  
  1155.             nError = translator->GetHeadwordTranslations( (const MTstring)head.c_str(), &headTranslations[0], &nSize );
  1156.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  1157.                 {
  1158.                 headTranslations = vector<MTChar>(nSize);
  1159.                 headTranslations[0] = 0;
  1160.                 nError = translator->GetHeadwordTranslations( (const MTstring)head.c_str(), &headTranslations[0], &nSize );
  1161.                 }
  1162.  
  1163.             //fill the headTransArray
  1164.             MTStringArray headTransArray;
  1165.             if (nError == MT_OK)
  1166.                 {
  1167.                 MTstringarray ptr;
  1168.                 ptr = &headTranslations[0];
  1169.                 unsigned curPos = 0;
  1170.                 wstring aHeadTran;
  1171.                 while( ptr - &headTranslations[0] < (int)nSize )
  1172.                     {
  1173.                     aHeadTran = wstring(ptr);
  1174.                     ptr += aHeadTran.size();
  1175.                     ++ptr;  //null-terminate current block
  1176.                     ++ptr; 
  1177.                     headTransArray.push_back(aHeadTran);
  1178.                     }
  1179.                 }
  1180.             return headTransArray;
  1181.             }
  1182.         
  1183.         /**This function retrieves the headword that alphabetically follows the specified
  1184.         reference word.
  1185.         \param head The word used to retrieve the next headword. This string is in
  1186.         word/attribute format and must contain a headword and translation field.
  1187.         \return The next headword that alphabetically follows the input headword.
  1188.           Possible errors:
  1189.         MTE_NO_TRANSLATOR - No language pair is set
  1190.         MTE_BARC_SERVER_ERROR - Internal engine error
  1191.         */
  1192.         wstring GetNextHeadword(const wstring & head)
  1193.             {
  1194.             MTerror nError = MT_OK;
  1195.             unsigned nSize = FAIR_SIZE;
  1196.             vector<MTChar> nextHeadTmp(nSize);
  1197.             nextHeadTmp[0] = 0;
  1198.  
  1199.             nError = translator->GetNextHeadword( (const MTstring)head.c_str(), &nextHeadTmp[0], &nSize );
  1200.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  1201.                 {
  1202.                 nextHeadTmp = vector<MTChar> (nSize);
  1203.                 nextHeadTmp[0] = 0;
  1204.                 nError = translator->GetNextHeadword( (const MTstring)head.c_str(), &nextHeadTmp[0], &nSize );
  1205.                 }
  1206.  
  1207.             wstring nextHead = L"";
  1208.             if (nError == MT_OK)
  1209.                 nextHead = wstring(&nextHeadTmp[0], nSize);
  1210.  
  1211.             return nextHead;
  1212.             }
  1213.         
  1214.         /**This function retrieves the headword that alphabetically precedes the 
  1215.         specified reference word.
  1216.         \param head The reference word used to retrieve the preceding headword. This string
  1217.         is in word/attribute format and must contain a headword and translation field.
  1218.         \return The previous headword that alphabetically precedes the input headword.
  1219.           Possible errors:
  1220.         MTE_NO_TRANSLATOR - No language pair is set
  1221.         MTE_BARC_SERVER_ERROR - Internal engine error
  1222.         */
  1223.         wstring GetPreviousHeadword(const wstring & head)
  1224.             {
  1225.             MTerror nError = MT_OK;
  1226.             unsigned nSize = FAIR_SIZE;
  1227.             vector<MTChar> preHeadTmp(nSize);
  1228.             preHeadTmp[0] = 0;
  1229.  
  1230.             nError = translator->GetPreviousHeadword( (const MTstring)head.c_str(), &preHeadTmp[0], &nSize );
  1231.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  1232.                 {
  1233.                 preHeadTmp = vector<MTChar> (nSize);
  1234.                 preHeadTmp[0] = 0;
  1235.                 nError = translator->GetPreviousHeadword( (const MTstring)head.c_str(), &preHeadTmp[0], &nSize );
  1236.                 }
  1237.  
  1238.             wstring preHead = L"";
  1239.             if (nError == MT_OK)
  1240.                 preHead = wstring(&preHeadTmp[0], nSize);
  1241.  
  1242.             return preHead;
  1243.             }
  1244.  
  1245.         
  1246.         /**This function retrieves a list of possible inflected forms, or morphologies,
  1247.         of the specified word.
  1248.         \param word The word for inflection patterns to be retrieved. This string is in
  1249.         word/attribute format and must contain a headword and translation field.
  1250.         \return The inflected forms or morphologies of the specified word.
  1251.           Possible errors:
  1252.         MTE_NO_TRANSLATOR - No language pair is set
  1253.         MTE_INVALID_WORD_ATTRIBUTE - <c>translation</c> missing one of: word, pofs or morphology
  1254.          MTE_UNFOUND_DICTIONARY_ENTRY - The word does not inflect (i.e. "the")
  1255.         MTE_BARC_SERVER_ERROR - Internal engine error
  1256.         */
  1257.         MTStringArray InflectWord(const wstring & word)
  1258.             {
  1259.             MTerror nError = MT_OK;
  1260.             unsigned nSize = LARGE_SIZE;
  1261.             vector <MTchar> inflectWords(nSize);
  1262.             inflectWords[0] = 0;
  1263.  
  1264.             nError = translator->InflectWord( (const MTstring)word.c_str(),  &inflectWords[0], &nSize );
  1265.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  1266.                 {
  1267.                 inflectWords = vector<MTchar>(nSize);
  1268.                 inflectWords[0] = 0;
  1269.                 nError = translator->InflectWord( (const MTstring)word.c_str(),  &inflectWords[0], &nSize );
  1270.                 }
  1271.  
  1272.             //fill the inflectWordArray
  1273.             MTStringArray inflectWordArray;
  1274.             if (nError == MT_OK)
  1275.                 {
  1276.                 MTstringarray ptr;
  1277.                 ptr = &inflectWords[0];
  1278.                 unsigned curPos = 0;
  1279.                 wstring aInflectWord;
  1280.                 while( ptr - &inflectWords[0] < (int)nSize )
  1281.                     {
  1282.                     aInflectWord = wstring(ptr);
  1283.                     ptr += aInflectWord.size();
  1284.                     ++ptr;  //null-terminate current block
  1285.                     ++ptr; 
  1286.                     inflectWordArray.push_back(aInflectWord);
  1287.                     }
  1288.                 }
  1289.             
  1290.             return inflectWordArray;
  1291.             }
  1292.         
  1293.         /**This function retrieves a list of lexical headwords that contain translations
  1294.         for the uninflected form of the specified word. It performs reverse morphological
  1295.         headword lookup using the specified word.
  1296.         \param word The word for lookup. This string is in word/attribute format and must
  1297.         contain a headword and translation field.
  1298.         \return The list of lexical headwords that contain translations for the uninflected
  1299.         form of the specified word.
  1300.           Possible errors:
  1301.         MTE_NO_TRANSLATOR - No language pair is set
  1302.          MTE_UNFOUND_DICTIONARY_ENTRY - The word was not found
  1303.         MTE_BARC_SERVER_ERROR - Internal engine error
  1304.         */
  1305.         MTStringArray Lookup (const wstring & word)
  1306.             {
  1307.             MTerror nError = MT_OK;
  1308.             unsigned nSize = LARGE_SIZE;
  1309.             vector<MTchar> lookupWords(nSize);
  1310.             lookupWords[0] = 0;
  1311.  
  1312.             nError = translator->Lookup( (const MTstring)word.c_str(),  &lookupWords[0], &nSize );
  1313.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  1314.                 {
  1315.                 lookupWords = vector<MTchar>(nSize);
  1316.                 lookupWords[0] = 0;
  1317.                 nError = translator->Lookup( (const MTstring)word.c_str(),  &lookupWords[0], &nSize );
  1318.                 }
  1319.  
  1320.             //fill the lookupWordArray
  1321.             MTStringArray lookupWordArray;
  1322.             if (nError == MT_OK)
  1323.                 {
  1324.                 MTstringarray ptr;
  1325.                 ptr = &lookupWords[0];
  1326.                 unsigned curPos = 0;
  1327.                 wstring aWord;
  1328.                 while( ptr - &lookupWords[0] < (int)nSize )
  1329.                     {
  1330.                     aWord = wstring(ptr);
  1331.                     ptr += aWord.size();
  1332.                     ++ptr;  //null-terminate current block
  1333.                     ++ptr; 
  1334.                     lookupWordArray.push_back(aWord);
  1335.                     }
  1336.                 }
  1337.  
  1338.             return lookupWordArray;
  1339.             }
  1340.         
  1341.         /**This function sets the translation entries for the specified headword.
  1342.         \param head The headword for which translations are set. This string must
  1343.         be in word/attribute format and must contain a headword field.
  1344.         \param transArray Translation entries for the specified headword. Each string
  1345.         is in word/attribute format and must contain a translation field.
  1346.         \return Error code.
  1347.           Possible errors:
  1348.         MTE_NO_TRANSLATOR - No language pair is set
  1349.         MTE_INVALID_WORD_ATTRIBUTE - <c>head</c> missing word attribute, or in any string from <c>transArray</c> 
  1350.         one of: translation, pofs, morphology is missing, or domain is invalid
  1351.          MTE_SETHEADWORD_FAILED - Internal engine error
  1352.         MTE_BARC_SERVER_ERROR - Internal engine error
  1353.         */
  1354.         MTResult SetHeadwordTranslations(const wstring & head, const MTStringArray & transArray)
  1355.             {
  1356.             MTerror nError = MT_OK;
  1357.  
  1358.             //put all the strings in buffer translations
  1359.             vector <MTchar> translations;
  1360.             MTStringArray::const_iterator iter = transArray.begin();
  1361.             for (; iter != transArray.end(); ++iter)
  1362.                 {
  1363.                 copy(iter->begin(), iter->end(), back_inserter(translations));
  1364.                 translations.push_back('\0');
  1365.                 }
  1366.             translations.push_back('\0');
  1367.  
  1368.             translator->SetHeadwordTranslations((const MTstring)head.c_str(), &translations[0]);
  1369.  
  1370.             return translator->GetMTError();
  1371.             }
  1372.  
  1373.         
  1374.         /**This function converts the specified Lexical Interchange File (LIF) to a
  1375.         dictionary that is compatible with the Barcelona engine.
  1376.         \param lifFileName The path and the file name of the LIF file to convert.
  1377.         \param cdsFileName The path where the dictionary file should be created.
  1378.         When a call is successful, the path contains a converted LIF file with the
  1379.         same name as the parameter \a lifFileName with a Ã´.CDSö extension.
  1380.         \param description A string that describes the contents of the dictionary.
  1381.         \return Error code.
  1382.           Possible errors:
  1383.         MTE_UNABLE_TO_CREATE_CDS_FILE =        300;    // Could not open a new .cds file
  1384.         MTE_UNABLE_TO_OPEN_LIF_FILE    =        301;    // Unable to open the specified LIF file
  1385.         MTE_MISSING_ENGINE_LANGUAGE_FILES =    302;    // Missing any one of the linguistic files needed by the engine
  1386.         MTE_HEADWORDS_OUT_OF_ORDER    =        303;    // Headwords are not in alphabetical order - non fatal
  1387.         MTE_INVALID_LEMMA_FIELD =            304;    // Lemma field in LIF file contans an error
  1388.         MTE_INVALID_TRANSLATION_FIELD =        305;    // Translation field in LIF file contains an error
  1389.         MTE_INVALID_POS_FIELD =                306;    // Error in POS field
  1390.         MTE_INVALID_ATTRIBUTE_FIELD =        307;    // Error in attribute field
  1391.         MTE_ENTRY_HAS_NO_GENDER =            308;    // For Portuguese only - when attribute field has the "NoArticle" attribute
  1392.         MTE_INVALID_COMMENT_FIELD =            309;    // Error in comment field
  1393.         MTE_INVALID_HEADWORD_FIELD =            310;    // Error in headword field
  1394.         MTE_INVALID_MORPHOLOGY_FIELD =        311;    // Invalid morphology field
  1395.         MTE_INVALID_INITIALS_FIELD =            312;    
  1396.         MTE_INVALID_DATE_FIELD =                313;
  1397.         MTE_TRANSLATION_INTEGRITY_ISSUE =    314;
  1398. //        */
  1399.         MTResult ConvertLIFtoDictionary  (const wstring & lifFileName, const wstring & cdsFileName, const wstring & description)
  1400.             {
  1401.             MTerror nError = MT_OK;
  1402.             nError = translator->ConvertLIFtoDictionary( (const MTstring)lifFileName.c_str(), 
  1403.                                                             (const MTstring)cdsFileName.c_str(), 
  1404.                                                             (const MTstring)description.c_str() );
  1405.             return translator->GetMTError();
  1406.             }
  1407.     };
  1408.  
  1409.  
  1410.  
  1411.  
  1412.     
  1413. /** \class MTtranslator3
  1414. Implements translation functions
  1415. */
  1416. class MTtranslator3 : public MTdictionary3
  1417.     {
  1418.     public:
  1419.         //! Default constructor
  1420.         MTtranslator3(){}
  1421.  
  1422.         
  1423.         //! Destructor
  1424.         virtual ~MTtranslator3(){}
  1425.       
  1426.        
  1427.         /**This function retrieves the array of subject domain identifiers that specify
  1428.         the lookup order of the subject domains. The first element in the array has the
  1429.         highest priority.
  1430.  
  1431.         The API obtains the current domain priority dictionary and returns an ordinal
  1432.         value that corresponds to the number of dictionary stacks. The stack value indicates
  1433.         the priority placement of the dictionaries.
  1434.         \param domains Upon completion, each element contains the list of subject domain
  1435.         identifiers specifying the prioritized subject domains. Absence of a subject domain
  1436.         from this list indicates that the translation engine ignores it.
  1437.         \return Error code.
  1438.           Possible errors:
  1439.         MTE_NO_TRANSLATOR - No language pair is set
  1440.         MTE_BARC_SERVER_ERROR - Internal engine error
  1441.         */
  1442.         MTResult GetDomainPriority(MTDomainArray & domains)
  1443.             {
  1444.             MTerror nError = MT_OK;
  1445.             unsigned nSize = FAIR_SIZE;
  1446.             
  1447.             vector<MTDomain> domainArray(nSize, 0);
  1448.  
  1449.             nError = translator->GetDomainPriority( &domainArray[0], &nSize );
  1450.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  1451.                 {
  1452.                 domainArray = vector<MTDomain>(nSize, 0);
  1453.                 nError = translator->GetDomainPriority( &domainArray[0], &nSize );
  1454.                 }
  1455.  
  1456.             if (nError == MT_OK)
  1457.                 copy (domainArray.begin(), domainArray.begin() + nSize, back_inserter(domains));
  1458.  
  1459.             return translator->GetMTError();
  1460.             }
  1461.  
  1462.                 
  1463.         /**This function returns the calling threadÆs last-error code value.
  1464.         A call to this function resets the threadÆs last-error code value to \a MT_OK.
  1465.         \return Error code.
  1466.           Possible errors: none
  1467.         */
  1468.         MTResult GetMTError()
  1469.             {
  1470.             return translator->GetMTError();
  1471.             }
  1472.  
  1473.        
  1474.         /**This function retrieves the identifier of the selected option value for the 
  1475.         specified option.
  1476.         \param option A translation option identifier whose selected value is returned.
  1477.         \return The selected option value for the specified option.
  1478.           Possible errors:
  1479.         MTE_NO_TRANSLATOR - No language pair is set
  1480.         MTE_INVALID_OPTION_IDENTIFIER - <c>option</c> parameter is not one of the values reported by <c>GetAvailableOptions</c>
  1481.         MTE_BARC_SERVER_ERROR - Internal engine error
  1482.         */
  1483.         MTOptionValue GetOptionValue (MTOption option)
  1484.             {
  1485.             MTOptionValue optValue = 0;
  1486.             translator->GetOptionValue( option, &optValue );
  1487.             return optValue;
  1488.             }
  1489.  
  1490.         
  1491.         /**This function retrieves the value of the specified global variable
  1492.         \param variable Global variable for which the value is returned
  1493.         \return The global variable value
  1494.           Possible errors:
  1495.         MTE_NO_TRANSLATOR - No language pair is set
  1496.         MTE_INVALID_PARAMETER - <c>variable</c> parameter is not one of the values reported by <c>GetAvailableVariables</c>
  1497.         MTE_BARC_SERVER_ERROR - Internal engine error
  1498.         */
  1499.         wstring GetVariableValue(const wstring& variable)
  1500.             {
  1501.             MTerror nError = MT_OK;
  1502.             unsigned nSize = FAIR_SIZE;
  1503.  
  1504.             vector <MTchar> val(nSize);
  1505.             val[0] = 0;            
  1506.             nError = translator->GetVariableValue((wchar_t*)variable.c_str(), &val[0], &nSize);
  1507.  
  1508.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  1509.                 {
  1510.                 val.resize(nSize);
  1511.                 val[0] = 0;
  1512.                 nError = translator->GetVariableValue((wchar_t*)variable.c_str(), &val[0], &nSize);
  1513.                 }
  1514.             if (nError == MT_OK)
  1515.                 return &val[0];
  1516.             else
  1517.                 return L"";
  1518.             }
  1519.  
  1520.                        
  1521.         /**This function parses and stores the word(s) from the input text into
  1522.         the array of strings.
  1523.         \param text The source sentence to be surface parsed.
  1524.         \param words Parsed words in source sentence.
  1525.         \return Error code.
  1526.           Possible errors:
  1527.         MTE_NO_TRANSLATOR - No language pair is set
  1528.         MTE_BARC_SERVER_ERROR - Internal engine error
  1529.         */
  1530.         MTResult ParseWordsFromSentence(const wstring & text, MTStringArray & words)
  1531.             {
  1532.             MTerror nError = MT_OK;
  1533.             unsigned nSize = LARGE_SIZE;
  1534.             vector<MTchar> parsedWords(nSize);
  1535.             parsedWords[0] = 0;
  1536.  
  1537.             nError = translator->ParseWordsFromSentence( (const MTstring)text.c_str(), &parsedWords[0], &nSize);
  1538.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  1539.                 {
  1540.                 parsedWords = vector<MTchar> (nSize);
  1541.                 parsedWords[0] = 0;
  1542.                 nError = translator->ParseWordsFromSentence((const MTstring)text.c_str(), &parsedWords[0], &nSize);
  1543.                 }
  1544.  
  1545.             //fill the parsedWords
  1546.             words.clear();
  1547.             if (nError == MT_OK)
  1548.                 {
  1549.                 MTstringarray ptr;
  1550.                 ptr = &parsedWords[0];
  1551.                 unsigned curPos = 0;
  1552.                 wstring aWord;
  1553.                 while( ptr - &parsedWords[0] < (int)nSize )
  1554.                     {
  1555.                     aWord = wstring(ptr);
  1556.                     ptr += aWord.size();
  1557.                     ++ptr;  //null-terminate current block
  1558.                     ++ptr; 
  1559.                     words.push_back(aWord);
  1560.                     }
  1561.                 }
  1562.  
  1563.             return translator->GetMTError();
  1564.             }
  1565.  
  1566.         
  1567.         /** This function tokenizes a sentence in a way that reflects the 
  1568.             initial level of nodes visible to a linguist. In contrast to ParseWordsFromSentence(),
  1569.             this also include lexicon lookup and postprocessing.
  1570.             <p> This function must not share memory with the functions in the underlying dlls
  1571.             it calls (BarcEng6.dll and BarcelonaEngineWrapper.dll).
  1572.             Thus, the vector of strings is passed as a simple byte stream.
  1573.             \param text The source sentence to be tokenized.
  1574.             \param tokens The tokens of the sentence. This is an output parameter.
  1575.             \return Error code. Possible error codes are
  1576.             <ul> 
  1577.             <li> MT_OK: No error occurred
  1578.             <li> MTE_NO_TRANSLATOR: No language pair is set
  1579.             <li> MTE_BARC_SERVER_ERROR: Internal engine error
  1580.             </ul>
  1581.         */
  1582.         MTResult EngineTokenize( const wstring & text, MTStringArray & tokens)
  1583.             {
  1584.             MTerror nError = MT_OK;
  1585.             unsigned nSize = LARGE_SIZE;
  1586.             vector<MTchar> parsedWords( nSize);
  1587.             parsedWords[0] = 0;
  1588.  
  1589.             nError = translator->EngineTokenize( (const MTstring)text.c_str(), &parsedWords[0], &nSize);
  1590.             if (nError == MTE_INSUFFICIENT_BUFFER )
  1591.                 {
  1592.                 // Provide a vector that is long enough and try again
  1593.                 parsedWords = vector<MTchar> (nSize);
  1594.                 parsedWords[0] = 0;
  1595.                 nError = translator->EngineTokenize( (const MTstring)text.c_str(), &parsedWords[0], &nSize);
  1596.                 }
  1597.  
  1598.             // Fill the result tokens
  1599.             tokens.clear();
  1600.             if (nError == MT_OK)
  1601.                 {
  1602.                 MTstringarray ptr;
  1603.                 ptr = &parsedWords[0];
  1604.                 unsigned curPos = 0;
  1605.                 wstring aWord;
  1606.                 while( ptr - &parsedWords[0] < (int)nSize )
  1607.                     {
  1608.                     aWord = wstring(ptr);
  1609.                     ptr += aWord.size();
  1610.                     ++ptr;  //null-terminate current block
  1611.                     ++ptr; 
  1612.                     tokens.push_back(aWord);
  1613.                     }
  1614.                 }
  1615.  
  1616.             return translator->GetMTError();
  1617.             }
  1618.         
  1619.  
  1620.         /**This function sets the lookup order of the subject domains. This determines
  1621.         the order in which the engine references the general dictionary and the subject 
  1622.         domains. If the same headword appears in more than one dictionary, the engine
  1623.         selects the translation that appears in the dictionary with the highest priority.
  1624.         \param domains The list of prioritized subject domain identifiers. If you leave
  1625.         a subject domain out of the list, it will be disabled.
  1626.         \return Error code.
  1627.           Possible errors:
  1628.         MTE_NO_TRANSLATOR - No language pair is set
  1629.         MTE_BARC_SERVER_ERROR - Internal engine error
  1630.         */
  1631.         MTResult SetDomainPriority(const MTDomainArray & domains)
  1632.             {
  1633.             unsigned nSize = domains.size();
  1634.             if (nSize == 0)
  1635.                 return MTE_INVALID_PARAMETER;
  1636.             
  1637.             MTdomainarray domainArray = (MTdomain*) (&domains[0]);
  1638.             translator->SetDomainPriority(domainArray, nSize );
  1639.  
  1640.             return translator->GetMTError();
  1641.             }
  1642.         
  1643.         /**This function sets the value of the specified translation option.
  1644.         \param option A translation option identifier.
  1645.         \param optValue A value for the option.
  1646.         \return Error code.
  1647.           Possible errors:
  1648.         MTE_NO_TRANSLATOR - No language pair is set
  1649.         MTE_INVALID_OPTION_IDENTIFIER - <c>option</c> parameter is not one of the values reported by <c>GetAvailableOptions</c>
  1650.         MTE_BARC_SERVER_ERROR - Internal engine error
  1651.         */
  1652.         MTResult SetOptionValue(const MTOption option, MTOptionValue optValue)
  1653.             {
  1654.             translator->SetOptionValue(option, optValue);
  1655.             return translator->GetMTError();
  1656.             }
  1657.  
  1658.         
  1659.         /**This function sets the value of the specified global variable
  1660.         \param variable Global variable name
  1661.         \param value A value for the variable
  1662.         \return Error code.
  1663.           Possible errors:
  1664.         MTE_NO_TRANSLATOR - No language pair is set
  1665.         MTE_INVALID_PARAMETER - Internal engine error
  1666.         MTE_BARC_SERVER_ERROR - Internal engine error        
  1667.         */
  1668.         MTResult SetVariableValue(const wstring& variable, const wstring& value)
  1669.             {            
  1670.             translator->SetVariableValue((const MTstring)variable.c_str(), (const MTstring)value.c_str());
  1671.             return translator->GetMTError();
  1672.             }
  1673.  
  1674.         /**This function returns an array containing offset/length pairs for the sentences
  1675.         contained in the text block or the document being translated.
  1676.         \param text The source sentence(s).
  1677.         \param offsets A reference to an MTOffsetLengthArray vector where each element
  1678.         is a SOffsetLengthEntry struct with two integer fields: offset and len.
  1679.         Upon completion, offset contains the offset position (starting from position 0)
  1680.         of a parsed sentence; len is the length of a parsed sentence.
  1681.         \return Error code.
  1682.           Possible errors:
  1683.         MTE_NO_TRANSLATOR - No language pair is set
  1684.         MTE_BARC_SERVER_ERROR - Internal engine error        
  1685.         */
  1686.         MTResult SurfaceParseSentences(const wstring & text, MTOffsetLengthArray & offsets)
  1687.             {
  1688.             MTerror nError = MT_OK;
  1689.             unsigned nSize = LARGE_SIZE;
  1690.             
  1691.             vector<unsigned> offsetArray(nSize, 0);
  1692.  
  1693.             nError = translator->SurfaceParseSentences( (const MTstring)text.c_str(), &offsetArray[0], &nSize );
  1694.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  1695.                 {
  1696.                 offsetArray = vector<unsigned> (nSize, 0);
  1697.                 nError = translator->SurfaceParseSentences( (const MTstring)text.c_str(), &offsetArray[0], &nSize );
  1698.                 }
  1699.  
  1700.             offsets.clear();
  1701.             for (unsigned i = 0; i < nSize; i += 2)
  1702.                 {
  1703.                 SOffsetLengthEntry entry = {offsetArray[i], offsetArray[i + 1]};
  1704.                 offsets.push_back(entry);
  1705.                 }
  1706.  
  1707.             return translator->GetMTError();
  1708.             }
  1709.                
  1710.         /**The most basic translation function of the SDK. It is intended for applications
  1711.         that only need to perform translation of a source text.
  1712.         \param source The text for translation. This string must be plain text
  1713.         (no formatting).
  1714.         \param translation Translated text.
  1715.         \return Error code.
  1716.           Possible errors:
  1717.         MTE_NO_TRANSLATOR - No language pair is set
  1718.         MTE_EMPTY_SOURCE - <c>source</c> is empty.
  1719.         MTE_BARC_SERVER_ERROR - Internal engine error        
  1720.         */
  1721.         MTResult Translate(const wstring & source, wstring & translation)
  1722.             {
  1723.             MTerror nError = MT_OK;
  1724.             unsigned nSize = LARGE_SIZE;
  1725.             vector<MTChar> transResult(nSize);
  1726.             transResult[0] = 0;
  1727.             
  1728.             nError = translator->Translate( (const MTstring)source.c_str(), &transResult[0], &nSize );
  1729.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  1730.                 {
  1731.                 transResult = vector<MTChar> (nSize);
  1732.                 transResult[0] = 0;
  1733.                 nError = translator->Translate( (const MTstring)source.c_str(), &transResult[0], &nSize );
  1734.                 }
  1735.  
  1736.             if ( nError == MT_OK)
  1737.                 translation = &transResult[0];
  1738.  
  1739.             return translator->GetMTError();
  1740.             }
  1741.         
  1742.         /**This function is intended for applications that need to preserve formatting or
  1743.         other non-text information in output. You must provide an array of character runs,
  1744.         with the source text. Character runs usually correspond to sequences of consecutive
  1745.         text that all share the same attributes. For example, a sequence of three bold words
  1746.         in a sentence would be a single character run, and the rest of the sentence would be
  1747.         considered one or more additional character run(s). During translation, the engine
  1748.         produces a mapping between translated text and the source text. Because translation
  1749.         often changes the order and placement of words, the text runs will not appear in the
  1750.         same order. As a result, the BackMapArray in C++ is a mapping
  1751.         between the translated runs and the source runs.
  1752.         \param source The text for translation. This string must be plain text (no formatting).
  1753.         \param translation The translated text.
  1754.         \param backMapArray A reference to an \a MTBackMapArray vector where each element is
  1755.         an \a SBackMapArrayEntry struct with four integer fields: \a targetOffSet, 
  1756.         \a targetLength, \a sourceOffSet and \a targetLength. Upon completion, \a targetOffset
  1757.         contains the 0-based index of the mapped translated word in the translated text, 
  1758.         \a targetLength shows the length of the mapped translated word, \a sourceOffSet
  1759.         contains the 0-based index of the mapped source word in the source text, and
  1760.         \a sourceLength shows the length of the mapped source word.
  1761.         \return Error code.
  1762.         MTE_NO_TRANSLATOR - No language pair is set
  1763.         MTE_EMPTY_SOURCE - <c>source</c> is empty.
  1764.         MTE_BARC_SERVER_ERROR - Internal engine error        
  1765.         */
  1766.         MTResult Translate(const wstring & source, wstring & translation, MTBackMapArray &backMapArray)
  1767.             {
  1768.             MTerror nError = MT_OK;
  1769.             unsigned nSize = LARGE_SIZE;
  1770.             vector<MTChar> transResult(nSize);
  1771.             transResult[0] = 0;
  1772.  
  1773.             unsigned srcSize = FAIR_SIZE;
  1774.             unsigned trgSize = FAIR_SIZE;
  1775.             unsigned associateSize = FAIR_SIZE;
  1776.             
  1777.             //srcArray contains source offset and run
  1778.             vector<unsigned> srcArray(srcSize);
  1779.             vector<unsigned> trgArray(trgSize);
  1780.             vector<unsigned> associateArray (associateSize);
  1781.             associateArray[0] = 0;
  1782.  
  1783.             //associateArray has [trgIndex, srcIndex, trgIndex, srcIndex, ......]
  1784.             nError = translator->Translate( (const MTstring)source.c_str(), 
  1785.                                                          &transResult[0], 
  1786.                                                         &nSize, 
  1787.                                                          &srcArray[0], 
  1788.                                                         &srcSize,
  1789.                                                          &trgArray[0],
  1790.                                                         &trgSize,
  1791.                                                          &associateArray[0],
  1792.                                                         &associateSize);
  1793.  
  1794.  
  1795.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  1796.                 {                
  1797.                 transResult = vector<MTChar>(nSize);
  1798.                 srcArray = vector<unsigned>(srcSize);
  1799.                 trgArray = vector<unsigned>(trgSize);
  1800.                 associateArray = vector<unsigned>(associateSize);
  1801.                 
  1802.                 nError = translator->Translate( (const MTstring)source.c_str(), 
  1803.                                                              &transResult[0], 
  1804.                                                             &nSize, 
  1805.                                                              &srcArray[0], 
  1806.                                                             &srcSize,
  1807.                                                              &trgArray[0],
  1808.                                                             &trgSize,
  1809.                                                              &associateArray[0],
  1810.                                                             &associateSize  );
  1811.                 }
  1812.  
  1813.             if ( nError == MT_OK)
  1814.                 {
  1815.                 translation = &transResult[0];
  1816.  
  1817.                 //construct the back mapping array
  1818.                 backMapArray.clear();
  1819.                 for(unsigned i = 0; i < associateSize; i += 2)
  1820.                     {
  1821.                     SBackMapArrayEntry mapEntry;
  1822.                     if(associateArray[i] >= 0 && associateArray[i] + 1 < trgSize)
  1823.                         {
  1824.                         mapEntry.targetOffset = trgArray[associateArray[i]];
  1825.                         mapEntry.targetLength = trgArray[associateArray[i] + 1];
  1826.                         }
  1827.  
  1828.                     if(associateArray[i + 1] >= 0 && associateArray[i + 1] + 1 < srcSize)
  1829.                         {
  1830.                         mapEntry.sourceOffset = srcArray[associateArray[i + 1]];
  1831.                         mapEntry.sourceLength = srcArray[associateArray[i + 1] + 1];
  1832.                         }
  1833.                     backMapArray.push_back(mapEntry);
  1834.                     }
  1835.                 }            
  1836.             return translator->GetMTError();
  1837.             }
  1838.                 
  1839.         /**This function translates an input sentence. It assumes the input text is a single
  1840.         sentence; therefore, the engine skips the sentence surface parsing.
  1841.         \param source The source sentence.
  1842.         \param translation The translated text.
  1843.         \return Error code.
  1844.         MTE_NO_TRANSLATOR - No language pair is set        
  1845.         MTE_BARC_SERVER_ERROR - Internal engine error        
  1846.         */
  1847.         MTResult TranslateSentence(const wstring & source, wstring & translation)
  1848.             {
  1849.             MTerror nError = MT_OK;
  1850.             unsigned nSize = LARGE_SIZE;
  1851.             vector <MTChar> transResult(nSize);
  1852.             transResult[0] = 0;
  1853.             
  1854.             nError = translator->TranslateSentence( (const MTstring)source.c_str(), &transResult[0], &nSize );
  1855.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  1856.                 {
  1857.                 transResult = vector<MTChar>(nSize);
  1858.                 transResult[0] = 0;
  1859.                 nError = translator->TranslateSentence( (const MTstring)source.c_str(), &transResult[0], &nSize );
  1860.                 }
  1861.  
  1862.             if ( nError == MT_OK)
  1863.                 translation = &transResult[0];
  1864.  
  1865.             return translator->GetMTError();
  1866.             }
  1867.         
  1868.         /**This function translates a sentence and outputs both the translated text and a
  1869.         source-target word association mapping. This call assumes that the input text is a
  1870.         single sentence; therefore, the engine skips sentence surface parsing.
  1871.         \param source The source sentence.
  1872.         \param translation The translated sentence.
  1873.         \param backMapArray A reference to an \a MTBackMapArray vector where each element is
  1874.         an \a SBackMapArrayEntry struct with four integer fields: \a targetOffSet, 
  1875.         \a targetLength, \a sourceOffSet and \a targetLength. Upon completion, \a targetOffset
  1876.         contains the 0-based index of the mapped translated word in the translated text, 
  1877.         \a targetLength shows the length of the mapped translated word, \a sourceOffSet
  1878.         contains the 0-based index of the mapped source word in the source text, and
  1879.         \a sourceLength shows the length of the mapped source word.
  1880.         \return Error code.        
  1881.         MTE_NO_TRANSLATOR - No language pair is set
  1882.         MTE_BARC_SERVER_ERROR - Internal engine error        
  1883.         */
  1884.         MTResult TranslateSentence(const wstring & source, wstring & translation, MTBackMapArray &backMapArray)
  1885.             {
  1886.             MTerror nError = MT_OK;
  1887.             unsigned nSize = LARGE_SIZE;
  1888.             vector <MTChar> transResult(nSize);
  1889.             transResult[0] = 0;
  1890.  
  1891.             unsigned srcSize = FAIR_SIZE;
  1892.             unsigned trgSize = FAIR_SIZE;
  1893.             unsigned associateSize = FAIR_SIZE;
  1894.             
  1895.             //srcArray contains source offset and run
  1896.             vector<unsigned> srcArray(srcSize);
  1897.             vector<unsigned> trgArray(trgSize);
  1898.             vector<unsigned> associateArray (associateSize);
  1899.  
  1900.  
  1901.             //associateArray has [trgIndex, srcIndex, trgIndex, srcIndex, ......]
  1902.             //to comply with the Barc Engine Wrapper, have to use this way, although inefficient.
  1903.             bool bResizeBuffer = true;
  1904.  
  1905.             while (bResizeBuffer)
  1906.                 {
  1907.                 nError = translator->TranslateSentence( (const MTstring)source.c_str(), 
  1908.                                                          &transResult[0], 
  1909.                                                         &nSize, 
  1910.                                                          &srcArray[0], 
  1911.                                                         &srcSize,
  1912.                                                          &trgArray[0],
  1913.                                                         &trgSize,
  1914.                                                          &associateArray[0],
  1915.                                                         &associateSize);
  1916.  
  1917.  
  1918.                 if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  1919.                     {
  1920.                     transResult = vector<MTChar>(nSize);
  1921.                     srcArray = vector<unsigned>(srcSize);
  1922.                     trgArray = vector<unsigned>(trgSize);
  1923.                     associateArray = vector<unsigned>(associateSize);
  1924.                     continue;
  1925.                     }
  1926.                 bResizeBuffer = false;
  1927.                 }
  1928.  
  1929.             if ( nError == MT_OK)
  1930.                 {
  1931.                 translation = &transResult[0];
  1932.  
  1933.                 //construct the back mapping array
  1934.                 backMapArray.clear();
  1935.                 for(unsigned i = 0; i < associateSize; i += 2)
  1936.                     {
  1937.                     SBackMapArrayEntry mapEntry;
  1938.                     if(associateArray[i] >= 0 && associateArray[i] + 1 < trgSize)
  1939.                         {
  1940.                         mapEntry.targetOffset = trgArray[associateArray[i]];
  1941.                         mapEntry.targetLength = trgArray[associateArray[i] + 1];
  1942.                         }
  1943.  
  1944.                     if(associateArray[i + 1] >= 0 && associateArray[i + 1] + 1 < srcSize)
  1945.                         {
  1946.                         mapEntry.sourceOffset = srcArray[associateArray[i + 1]];
  1947.                         mapEntry.sourceLength = srcArray[associateArray[i + 1] + 1];
  1948.                         }
  1949.                     backMapArray.push_back(mapEntry);
  1950.                     }
  1951.                 }
  1952.  
  1953.             return translator->GetMTError();
  1954.             }
  1955.  
  1956.         
  1957.         /**This function translates the specified source word from the active source
  1958.         language to the active target language. This call retrieves all possible
  1959.         translations (headwords) for the word found in the active subject dictionaries.
  1960.         \param source The source word for translation. This string requires the word field,
  1961.         and must be in word/attribute format.
  1962.         \param transArray The translations for the specified word. Each string in this array
  1963.         is in word/attribute format and contains a translation field.
  1964.         \return Error code.
  1965.         MTE_NO_TRANSLATOR - No language pair is set
  1966.         MTE_EMPTY_SOURCE - <c>source</c> is empty.
  1967.         MTE_INVALID_WORD_ATTRIBUTE - word attribute is missing in <c>source</c> parameter
  1968.         MTE_BARC_SERVER_ERROR - Internal engine error        
  1969.         */
  1970.         MTResult TranslateWord (const wstring & source, MTStringArray & transArray)
  1971.             {
  1972.             MTerror nError = MT_OK;
  1973.             unsigned nSize = LARGE_SIZE;
  1974.             vector<MTchar> translations(nSize);
  1975.             translations[0] = 0;
  1976.  
  1977.             nError = translator->TranslateWord( (const MTstring)source.c_str(), &translations[0], &nSize);
  1978.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  1979.                 {
  1980.                 translations = vector<MTchar>(nSize);
  1981.                 translations[0] = 0;
  1982.                 nError = translator->TranslateWord( (const MTstring)source.c_str(), &translations[0], &nSize);
  1983.                 }
  1984.  
  1985.             //fill the transArray
  1986.             transArray.clear();
  1987.             if (nError == MT_OK)
  1988.                 {
  1989.                 MTstringarray ptr;
  1990.                 ptr = &translations[0];
  1991.                 unsigned curPos = 0;
  1992.                 wstring aWord;
  1993.                 while( ptr - &translations[0] < (int)nSize )
  1994.                     {
  1995.                     aWord = wstring(ptr);
  1996.                     ptr += aWord.size();
  1997.                     ++ptr;  //null-terminate current block
  1998.                     ++ptr; 
  1999.                     transArray.push_back(aWord);
  2000.                     }
  2001.                 }
  2002.  
  2003.             return translator->GetMTError();
  2004.             }
  2005.         
  2006.         /**This function translates the specified source phrase from the active source
  2007.         language to the active target language. This call retrieves all possible
  2008.         translations (headwords) for the phrase found in the active subject dictionaries.
  2009.         \param source The source phrase for translation. This string requires the phrase field,
  2010.         and must be in word/attribute format.
  2011.         \param transArray The translations for the specified phrase. Each string in this array
  2012.         is in word/attribute format and contains a translation field.
  2013.         \return Error code.
  2014.         MTE_NO_TRANSLATOR - No language pair is set
  2015.         MTE_EMPTY_SOURCE - <c>source</c> is empty.
  2016.         MTE_INVALID_WORD_ATTRIBUTE - phrase attribute is missing in <c>source</c> parameter
  2017.         MTE_BARC_SERVER_ERROR - Internal engine error        
  2018.         */
  2019.         MTResult TranslatePhrase (const wstring & source, MTStringArray & transArray)
  2020.             {
  2021.             if (source.size() == 0)
  2022.                 return MTE_EMPTY_SOURCE;
  2023.  
  2024.             MTerror nError = MT_OK;
  2025.             unsigned nSize = LARGE_SIZE;
  2026.             vector<MTchar> translations(nSize);
  2027.             translations[0] = 0;
  2028.  
  2029.             nError = translator->TranslatePhrase( (const MTstring)source.c_str(), &translations[0], &nSize);
  2030.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  2031.                 {
  2032.                 translations = vector<MTchar>(nSize);
  2033.                 translations[0] = 0;
  2034.                 nError = translator->TranslatePhrase( (const MTstring)source.c_str(), &translations[0], &nSize);
  2035.                 }
  2036.  
  2037.             //fill the transArray
  2038.             transArray.clear();
  2039.             if (nError == MT_OK)
  2040.                 {
  2041.                 MTstringarray ptr;
  2042.                 ptr = &translations[0];
  2043.                 unsigned curPos = 0;
  2044.                 wstring aWord;
  2045.                 while( ptr - &translations[0] < (int)nSize )
  2046.                     {
  2047.                     aWord = wstring(ptr);
  2048.                     ptr += aWord.size();
  2049.                     ++ptr;  //null-terminate current block
  2050.                     ++ptr; 
  2051.                     transArray.push_back(aWord);
  2052.                     }
  2053.                 }
  2054.  
  2055.             return translator->GetMTError();
  2056.             }
  2057.  
  2058.         //////////////////////////////////////////////////////////////////////
  2059.         // Following is a large group of confidence score functions
  2060.         //
  2061.  
  2062.         /**Returns the names of the existing confidence models. This function loads 
  2063.         all available DLLs with different confidence score models and queries them 
  2064.         for CM names. The each DLL which contains a confidence score model will have 
  2065.         an API which will provide a name of the model this DLL contains. 
  2066.         \param models [OUT] This is an output parameter. Upon return from the function, 
  2067.         models will contain the names of the confidence models that are currently 
  2068.         available in the engine. Each name is a Unicode string. The function gets 
  2069.         this string from the DLL containing individual CM. If an error occurs during 
  2070.         the execution of this function, the returned vector will be empty and function 
  2071.         will return MTE_CM_FAILURE. If there are no DLLs  containing confidence score 
  2072.         models, the vector will be empty and function will return MT_OK.
  2073.         \return Error code.
  2074.         MT_OK: The function was executed successfully. 
  2075.         MTE_BARC_SERVER_ERROR: Unexpected error.        
  2076.         */
  2077.         MTResult GetConfidenceModels(MTStringArray &models)
  2078.             {
  2079.             MTerror nError = MT_OK;
  2080.  
  2081.             unsigned nSize = LARGE_SIZE;
  2082.             vector<MTchar> tmpArray(nSize);
  2083.  
  2084.             nError = translator->GetConfidenceModels(&tmpArray[0], &nSize);
  2085.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  2086.                 {
  2087.                 tmpArray = vector<MTchar>(nSize);
  2088.                 tmpArray[0] = 0;
  2089.                 nError = translator->GetConfidenceModels(&tmpArray[0], &nSize);
  2090.                 }
  2091.             // transfer the data to output parameter
  2092.             models.clear();
  2093.             if (nError == MT_OK)
  2094.                 {
  2095.                 MTstringarray ptr;
  2096.                 ptr = &tmpArray[0];
  2097.                 unsigned curPos = 0;
  2098.                 wstring aWord;
  2099.                 while( ptr - &tmpArray[0] < (int)nSize )
  2100.                     {
  2101.                     aWord = wstring(ptr);
  2102.                     ptr += aWord.size();
  2103.                     ++ptr;  //null-terminate current block
  2104.                     ++ptr; 
  2105.                     models.push_back(aWord);
  2106.                     }
  2107.                 }
  2108.             return translator->GetMTError();
  2109.             }
  2110.  
  2111.         /**Select a confidence model for future operations. 
  2112.         Selecting a confidence model is the first step needed in obtaining confidence 
  2113.         scores. All other SDK functions related to confidence measures except 
  2114.         MTtranslator3::GetConfidenceMethods operate on the currently selected model. 
  2115.         During the runtime of an SDK instance, several confidence methods can be 
  2116.         selected (and activated and executed). Selecting a confidence measure does 
  2117.         not invalidate or remove the previously selected confidence score model.
  2118.         Only one instance of a particular confidence model exists at any given time. 
  2119.         Thus, it is not possible to use two identical confidence score models with 
  2120.         differing configuration in the same SDK process.
  2121.         \param model A Unicode string identifying the confidence measure to be used. 
  2122.         This should be identical to one of the names returned in GetConfidenceModels(). 
  2123.         \return Error code.
  2124.         MT_OK - The function was executed successfully. 
  2125.         MTE_INVALID_PARAMETER - The name of the confidence method is invalid. No such 
  2126.                                 method exists.
  2127.         MTE_BARC_SERVER_ERROR - Unexpected error.
  2128.         */
  2129.         MTResult SelectConfidenceModel(const wstring &model)
  2130.             {
  2131.             MTerror nError = MT_OK;
  2132.             nError = translator->SelectConfidenceModel((const MTstring)model.c_str());
  2133.             return translator->GetMTError();
  2134.             }
  2135.  
  2136.         /**Activate the current confidence model. 
  2137.         This function activates the previously selected (and possibly configured) 
  2138.         confidence score model. Activation is a prerequisite to executing a confidence 
  2139.         measure. The reason for explicitly separating the activation instead of just 
  2140.         performing initialization upon first use is to allow the implementor to place 
  2141.         time-consuming initialization code here. 
  2142.         This function can only be called of a confidence score model was selected earlier. 
  2143.         This function needs to be called before executing a confidence measure for 
  2144.         the first time.
  2145.         \return Error code
  2146.         MT_OK - The function was executed successfully. 
  2147.         MTE_BARC_SERVER_ERROR - Unexpected error.
  2148.         MTE_NO_CM_SELECTED - Confidence measure is not selected.
  2149.         */
  2150.         MTResult ActivateConfidenceMeasure()
  2151.             {
  2152.             MTerror nError = MT_OK;
  2153.             nError = translator->ActivateConfidenceMeasure();
  2154.             return translator->GetMTError();
  2155.             }
  2156.  
  2157.         /**Deactivate the current confidence score model. 
  2158.         \return Error code
  2159.         MT_OK - The function was executed successfully. 
  2160.         MTE_BARC_SERVER_ERROR - Unexpected error.
  2161.         */
  2162.         MTResult DeactivateConfidenceMeasure()
  2163.             {
  2164.             MTerror nError = MT_OK;
  2165.             nError = translator->DeactivateConfidenceMeasure();
  2166.             return translator->GetMTError();
  2167.             }
  2168.  
  2169.         /**Return the available options for the current confidence measure. Different 
  2170.         methods may have different list of options. These options will be used to 
  2171.         configure selected confidence method.
  2172.         \param options [OUT]. Upon return from the function options will contain 
  2173.         a list of all available options for currently selected confidence method. 
  2174.         \return Error code
  2175.         MT_OK - The function was executed successfully. 
  2176.         MTE_BARC_SERVER_ERROR - Unexpected error.
  2177.         MTE_NO_CM_SELECTED - Confidence measure is not selected.
  2178.         */
  2179.         MTResult GetConfidenceOptions(MTStringArray &options)
  2180.             {
  2181.             MTerror nError = MT_OK;
  2182.             unsigned nSize = LARGE_SIZE;
  2183.             vector<MTchar> tmpArray(nSize);
  2184.             nError = translator->GetConfidenceOptions(&tmpArray[0], &nSize);
  2185.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  2186.                 {
  2187.                 tmpArray = vector<MTchar>(nSize);
  2188.                 tmpArray[0] = 0;
  2189.                 nError = translator->GetConfidenceOptions(&tmpArray[0], &nSize);
  2190.                 }
  2191.             // transfer the data to output parameter
  2192.             options.clear();
  2193.             if (nError == MT_OK)
  2194.                 {
  2195.                 MTstringarray ptr;
  2196.                 ptr = &tmpArray[0];
  2197.                 unsigned curPos = 0;
  2198.                 wstring aWord;
  2199.                 while( ptr - &tmpArray[0] < (int)nSize )
  2200.                     {
  2201.                     aWord = wstring(ptr);
  2202.                     ptr += aWord.size();
  2203.                     ++ptr;  //null-terminate current block
  2204.                     ++ptr; 
  2205.                     options.push_back(aWord);
  2206.                     }
  2207.                 }
  2208.             return translator->GetMTError();
  2209.             }
  2210.  
  2211.         /**Return the available values for a confidence measure option. Every option 
  2212.         is represented as a string. It is a responsibility of particular confidence 
  2213.         score model to convert the string value of the option to an appropriate type.
  2214.         \param option [IN]. Name of the option. This must be one of the options 
  2215.         returned in GetConfidenceOptions call. 
  2216.         \param values [OUT]. All possible values which can be assigned to the option. 
  2217.         If values cannot be enumerated, this vector contains 0 elements. In this case 
  2218.         any string value can be assigned to the option. 
  2219.         \return Error code
  2220.         MT_OK - The function was executed successfully. 
  2221.         MTE_BARC_SERVER_ERROR - Unexpected error.
  2222.         MTE_NO_CM_SELECTED - Confidence measure is not selected.
  2223.         MTE_INVALID_PARAMETER - The name of the option is invalid. No such option exists. 
  2224.         */
  2225.         MTResult GetConfidenceOptionValues(const wstring &option, MTStringArray &values)
  2226.             {
  2227.             MTerror nError = MT_OK;
  2228.             unsigned nSize = LARGE_SIZE;
  2229.             vector<MTchar> tmpArray(nSize);
  2230.             nError = translator->GetConfidenceOptionValues(
  2231.                 (const MTstring)option.c_str(), &tmpArray[0], &nSize);
  2232.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  2233.                 {
  2234.                 tmpArray = vector<MTchar>(nSize);
  2235.                 tmpArray[0] = 0;
  2236.                 nError = translator->GetConfidenceOptionValues(
  2237.                         (const MTstring)option.c_str(), &tmpArray[0], &nSize);
  2238.                 }
  2239.             // transfer the data to output parameter
  2240.             values.clear();
  2241.             if (nError == MT_OK)
  2242.                 {
  2243.                 MTstringarray ptr;
  2244.                 ptr = &tmpArray[0];
  2245.                 unsigned curPos = 0;
  2246.                 wstring aWord;
  2247.                 while( ptr - &tmpArray[0] < (int)nSize )
  2248.                     {
  2249.                     aWord = wstring(ptr);
  2250.                     ptr += aWord.size();
  2251.                     ++ptr;  //null-terminate current block
  2252.                     ++ptr; 
  2253.                     values.push_back(aWord);
  2254.                     }
  2255.                 }
  2256.             return translator->GetMTError();
  2257.             }
  2258.  
  2259.         /**Get the type of the option. Options are defined by individual confidence 
  2260.         score model. They may contain file names, numerical or string values etc. 
  2261.         In order to assign some value to the option the client application should know 
  2262.         what kind of values each individual option can accept.
  2263.         \param option [IN]. Name of the option. This must be one of the options returned 
  2264.         in GetConfidenceOptions call. 
  2265.         \param type [OUT]. One of predefined types. All available types are listed 
  2266.         in enumeration:
  2267.         enum 
  2268.             {StringOption = 0, 
  2269.             NumericalOption = 1, 
  2270.             BooleanOptin = 2, 
  2271.             FileNameOption = 3};
  2272.         Regardless of the optionÆs type the option may accept only string values. 
  2273.         It is responsibility of the selected model to convert the option into 
  2274.         appropriate type and validate it.
  2275.         \return Error code
  2276.         MT_OK - The function was executed successfully. 
  2277.         MTE_BARC_SERVER_ERROR - Unexpected error.
  2278.         MTE_NO_CM_SELECTED - Confidence measure is not selected.
  2279.         MTE_INVALID_PARAMETER - The name of the option is invalid. No such option exists.
  2280.         */
  2281.         MTResult GetConfidenceOptionType(const wstring &option, int &type)
  2282.             {
  2283.             MTerror nError = MT_OK;
  2284.             nError = translator->GetConfidenceOptionType(
  2285.                 (const MTstring)option.c_str(), type);
  2286.             return translator->GetMTError();
  2287.             }
  2288.  
  2289.         /**Get the current value of a confidence measure option. 
  2290.         \param option [IN]. Name of the option. This must be one of the options 
  2291.         returned in GetConfidenceOptions call. 
  2292.         \param value [OUT]. The current value of the option converted to 
  2293.         the string. Even if the option is number or Boolean the value can be 
  2294.         passed between caller and confidence score API only as a string. 
  2295.         \return Error code
  2296.         MT_OK - The function was executed successfully. 
  2297.         MTE_BARC_SERVER_ERROR - Unexpected error.
  2298.         MTE_NO_CM_SELECTED - Confidence measure is not selected.
  2299.         MTE_INVALID_PARAMETER - The name of the option is invalid. No such option exists.
  2300.         */
  2301.         MTResult GetConfidenceOptionValue(const wstring &option, wstring &value)
  2302.             {
  2303.             MTerror nError = MT_OK;
  2304.             unsigned nSize = LARGE_SIZE;
  2305.             vector<MTchar> tmpArray(LARGE_SIZE);
  2306.             nError = translator->GetConfidenceOptionValue(
  2307.                 (const MTstring)option.c_str(), &tmpArray[0], &nSize);
  2308.             if (nError == MTE_INSUFFICIENT_BUFFER )  // insufficient buffer
  2309.                 {
  2310.                 tmpArray = vector<MTchar>(nSize);
  2311.                 tmpArray[0] = 0;
  2312.                 nError = translator->GetConfidenceOptionValue(
  2313.                     (const MTstring)option.c_str(), &tmpArray[0], &nSize);
  2314.                 }
  2315.             if (nError == MT_OK)
  2316.                 {
  2317.                 value = &tmpArray[0];
  2318.                 }
  2319.             return translator->GetMTError();
  2320.             }
  2321.  
  2322.         /**Set the value of a confidence score model option. The option will be assigned 
  2323.         with string value. The currently selected confidence method will convert 
  2324.         the value to an appropriate type (see GetConfidenceOptionType), validate 
  2325.         the value and check if the value can be used. E.g. if option is a file name 
  2326.         it will check if the file is present; if option is number it will check if 
  2327.         the entered value falls within acceptable number range, etc. 
  2328.         \param option [IN]. The name of the option. This should be identical 
  2329.         to one of the options returned in GetConfidenceOptions().
  2330.         \param value [IN]. The value of the option. The string value of the option. 
  2331.         This parameter is always string even if the option can accept only numerical 
  2332.         values. The currently selected confidence score will cast the value 
  2333.         to appropriate type and perform the validation. 
  2334.         \return Error code
  2335.         MT_OK - The function was executed successfully. 
  2336.         MTE_BARC_SERVER_ERROR - Unexpected error.
  2337.         MTE_NO_CM_SELECTED - Confidence measure is not selected.
  2338.         MTE_INVALID_PARAMETER - The name of the option is invalid. No such option exists.
  2339.         MTE_INVALID_VALUE: The value cannot be used. 
  2340.         */
  2341.         MTResult SetConfidenceOptionValue(const wstring &option, const wstring &value)
  2342.             {
  2343.             MTerror nError = MT_OK;
  2344.             nError = translator->SetConfidenceOptionValue(
  2345.                 (const MTstring)option.c_str(), (const MTstring)value.c_str());
  2346.             return translator->GetMTError();
  2347.             }
  2348.  
  2349.         /**Return the possible range of scores for the current confidence measure. 
  2350.         This function can be called after selected confidence score method is activated. 
  2351.         The range can be different for different confidence score methods. 
  2352.         There is no way to estimate the possible values before the method 
  2353.         is selected, configured and activated. The meaning of return parameters may be 
  2354.         also different for different methods. E.g. some method may return minValue = 0 
  2355.         and maxValue = 1 meaning that result can be anywhere between 0 and 1, 
  2356.         like 0.5 or 0.8 etc; another method may return same values meaning they are 
  2357.         FALSE and TRUE and result can be only 0 or 1. The meaning of min and max 
  2358.         value will be provided in the documentation for every available confidence 
  2359.         score method.
  2360.         \param minValue [OUT]. Contains smallest value which can be returned 
  2361.         by function GetConfidenceScore().
  2362.         \param maxValue [OUT]. Contains biggest value which can be returned 
  2363.         by function GetConfidenceScore()
  2364.         \return Error code
  2365.         MT_OK - The function was executed successfully. 
  2366.         MTE_BARC_SERVER_ERROR - Unexpected error.
  2367.         MTE_NO_CM_SELECTED - Confidence measure is not selected.
  2368.         */
  2369.         MTResult GetConfidenceRange(double &minValue, double &maxValue)
  2370.             {
  2371.             MTerror nError = MT_OK;
  2372.             nError = translator->GetConfidenceRange(minValue, maxValue);
  2373.             return translator->GetMTError();
  2374.             }
  2375.         /**
  2376.         Produce the confidence score for a sentence pair basing on currently 
  2377.         selected model. Before calling this function the confidence score model 
  2378.         has to be selected, configured and activated. This function may use the engine 
  2379.         data therefore it guarantees to return correct data only if it is called 
  2380.         immediately after translation and before any other engine calls. Details 
  2381.         of implementation depend on particular confidence score method and 
  2382.         should be described in method documentation.
  2383.         \param source [IN]. Source sentence
  2384.         \param translation [IN]. Translated sentence
  2385.         \param score [OUT]. Contains the resulting confidence score 
  2386.         \return Error code
  2387.         MT_OK - The function was executed successfully. 
  2388.         MTE_BARC_SERVER_ERROR - Unexpected error.
  2389.         MTE_NO_CM_SELECTED - Confidence measure is not selected.
  2390.         */
  2391.         MTResult GetConfidenceScore(const wstring &source, const wstring &translation, double &score)
  2392.             {
  2393.             MTerror nError = MT_OK;
  2394.             nError = translator->GetConfidenceScore(
  2395.                 (const MTstring)source.c_str(), (const MTstring)translation.c_str(), score);
  2396.             return translator->GetMTError();
  2397.             }
  2398.         //
  2399.         // End of confidence score methods
  2400.         ///////////////////////////////////////////////////////////////////
  2401.     };
  2402.  
  2403.  
  2404.  
  2405.  
  2406.  
  2407. #ifdef MTAPI_EXPORT
  2408.     #undef MTAPI_EXPORT
  2409.     #define MTAPI_EXPORT    __declspec(dllexport)
  2410. #else
  2411.     #define MTAPI_EXPORT    __declspec(dllexport)
  2412. #endif
  2413.  
  2414.  
  2415.  
  2416. #ifndef MTAPI_LANG_ENGLISH
  2417. #define  MTAPI_LANG_ENGLISH     0x00000009  // English
  2418. #endif
  2419.  
  2420. #ifndef MTAPI_LANG_FRENCH
  2421. #define  MTAPI_LANG_FRENCH      0x0000000C  // French
  2422. #endif
  2423.  
  2424. #ifndef MTAPI_LANG_GERMAN
  2425. #define  MTAPI_LANG_GERMAN      0x00000007  // German
  2426. #endif
  2427.  
  2428. #ifndef MTAPI_LANG_ITALIAN
  2429. #define  MTAPI_LANG_ITALIAN     0x00000010  // Italian
  2430. #endif
  2431.  
  2432. #ifndef MTAPI_LANG_PORTUGUESE
  2433. #define  MTAPI_LANG_PORTUGUESE  0x00000016  // Portuguese
  2434. #endif
  2435.  
  2436. #ifndef MTAPI_LANG_SPANISH
  2437. #define  MTAPI_LANG_SPANISH     0x0000000a  // Spanish
  2438. #endif
  2439.  
  2440. #ifndef MTAPI_LANG_JAPANESE
  2441. #define  MTAPI_LANG_JAPANESE    0x00000011  // Japanese
  2442. #endif
  2443.  
  2444. #ifndef MTAPI_LANG_NEUTRAL
  2445. #define  MTAPI_LANG_NEUTRAL     0x00000000  // Neutral
  2446. #endif
  2447.  
  2448.  
  2449. // following are defines for every API call.  
  2450. const short ISCOUNTAVAILABLEINTERFACELANGUAGES =  1;
  2451. const short    ISCOUNTAVAILABLELANGUAGEPAIRS    =      2;
  2452. const short    ISCOUNTAVAILABLEOPTIONS          =      3;
  2453. const short    ISCOUNTAVAILABLEOPTIONVALUES     =      4;
  2454. const short ISCOUNTAVAILABLEPARTSOFSPEECH    =    5;
  2455. const short ISCOUNTAVAILABLESUBJECTDOMAINS   =    6;
  2456. const short ISCREATEDOMAIN                   =    7;
  2457. const short ISCREATETRANSLATION                 =    8;
  2458. const short ISDELETETRANSLATION                 =    9;
  2459. const short ISGETACTIVELANGUAGEPAIR             =   10;
  2460. const short ISGETAVAILABLEINTERFACELANGUAGES =   11;     
  2461. const short ISGETAVAILABLELANGUAGEPAIRS      =   12;
  2462. const short ISGETAVAILABLEMORPHOLOGIES         =     13;
  2463. const short ISGETAVAILABLEOPTIONS             =   14;
  2464. const short ISGETAVAILABLEOPTIONVALUES         =      15;
  2465. const short ISGETAVAILABLEPARTSOFSPEECH         =     16;
  2466. const short ISGETAVAILABLESUBJECTDOMAINS     =     17;
  2467. const short ISGETDOMAINPRIORITY                 =   19;
  2468. const short ISGETHEADWORDTRANSLATIONS         =   21;
  2469. const short ISGETLANGUAGEDESCRIPTION         =   22;   
  2470. const short ISGETNEXTHEADWORD                =     23;
  2471. const short ISGETOPTIONDESCRIPTION             =   24;
  2472. const short ISGETOPTIONVALUE                 =   25;
  2473. const short ISGETOPTIONVALUEDESCRIPTION         =     26;
  2474. const short ISGETPARTOFSPEECHDESCRIPTION     =   27;
  2475. const short ISGETPREVIOUSHEADWORD             =   28;
  2476. const short ISGETSUBJECTDOMAINDESCRIPTION     =   29;    
  2477. const short ISINFLECTWORD                     =   31;
  2478. const short ISLOADALLLANGUAGEPAIRS           =   32;
  2479. const short ISLOADCUSTOMDICTIONARY           =   33;
  2480. const short ISLOADDOMAINDICTIONARY           =   34;
  2481. const short ISLOADLANGUAGEPAIR               =   35;
  2482. const short ISLOOKUP                         =   36;
  2483. const short ISPARSEWORDSFROMSENTENCE         =   37; 
  2484. const short ISRELEASEMT                      =   39;
  2485. const short ISSETACTIVELANGUAGEPAIR             =     40;
  2486. const short ISSETDOMAINPRIORITY                 =   41;
  2487. const short ISSETHEADWORDTRANSLATIONS         =   42;    
  2488. const short ISSETOPTIONVALUE                 =   43;
  2489. const short ISSURFACEPARSESENTENCES             =   44;
  2490. const short ISTRANSLATE                         =   49;
  2491. const short ISTRANSLATEBACKMAP                 =   50;
  2492. const short ISTRANSLATESENTENCE                 =   52;
  2493. const short ISTRANSLATESENTENCEBACKMAP         =   53;
  2494. const short ISTRANSLATEWORD                  =   54;
  2495. const short ISUNLOADALLLANGUAGEPAIRS         =   55;
  2496. const short ISUNLOADCUSTOMDICTIONARY         =   56;
  2497. const short ISUNLOADDOMAINDICTIONARY         =   57;
  2498. const short ISUNLOADLANGUAGEPAIR             =   58;
  2499.  
  2500. const short ISGETHEADWORD                     =   62;
  2501. const short ISGETHEADWORDCOUNT                 =   63;
  2502. const short ISGETHEADWORDINDEX                 =   64;
  2503. const short ISCONVERTLIFTODICTIONARY         =   65;
  2504.  
  2505. const short ISCOUNTAVAILABLEVARIABLES        =   66;
  2506. const short ISGETAVAILABLEVARIABLES          =   67;
  2507. const short ISGETVARIABLEVALUE               =   68;
  2508. const short ISSETVARIABLEVALUE               =   69;
  2509. const short ISTRANSLATEPHRASE                =   70;
  2510. const short ISENGINETOKENIZE                 =   71;
  2511. // <confidence score functions>
  2512. const short ISGETCONFIDENCEMODELS             =   72;
  2513. const short ISSELECTCONFIDENCEMODEL           =   73;
  2514. const short ISACTIVATECONFIDENCEMEASURE       =   74;
  2515. const short ISDEACTIVATECONFIDENCEMEASURE     =   75;
  2516. const short ISGETCONFIDENCEOPTIONS            =   76;
  2517. const short ISGETCONFIDENCEPOTIONVALUES       =   77;
  2518. const short ISGETCONFIDENCEOPIONTYPE          =   78;
  2519. const short ISGETCONFIDENCEOPTIONVALUE        =   79;
  2520. const short ISSETCONFIDENCEOPTIONVALUE        =   80;
  2521. const short ISGETCONFIDENCERANGE              =   81;
  2522. const short ISGETCONFIDENCESCORE              =   82;
  2523. // </confidence score functions>
  2524.  
  2525. //extern "C" MTAPI_EXPORT  MTtranslator3 * CreateTranslator();
  2526. //extern "C" MTAPI_EXPORT  void   DeleteTranslator(MTtranslator3 *);
  2527.  
  2528. //typedef MTtranslator3 * (MTAPI_CALL *fnCreateTranslator)();
  2529. //typedef void (MTAPI_CALL *fnDeleteTranslator)(MTtranslator3 *);
  2530.  
  2531.  
  2532. }   // end namespace MTCPlusPlusAPI
  2533.  
  2534.  
  2535. #endif  //  MTCPlusPlusAPI_H
  2536.